| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 693 人关注过本帖
标题:[求助]
取消只看楼主 加入收藏
yuanyuan
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-5-11
收藏
 问题点数:0 回复次数:3 
[求助]
#include  <stdio.h>
#include  <malloc.h>

typedef struct list_t
{
    int id;
    struct list_t *prior;                 
    struct list_t *next;     
}LIST;

void add_node(int n, LIST *p)
{
    LIST *head, *pr, *pp;
    int i;

    pr = head; p = head->next;
    while(p != NULL && p -> id < n) {
        pr = p;
        p = p -> next;
    }
    if((pp = (LIST *)malloc(sizeof(LIST))) == NULL) {
        printf("Insertion is not success!");
         
    } else {
        pp -> id = n;
        pp -> next = pr->next;
        pr -> next = pp;
    }
}

void remove_node(int id)
{
    LIST * head, *p1, *p2;
    int n;
    if(head == NULL) {
        printf("\nlist null !\n");
         
    }
    p1 = head;
    while(id != p1 -> id && p1 -> next != NULL) {
        p2 = p1;
        p1 = p1 -> next;
    }
    if(id == p1 -> id) {
        if(p1 == head) {
            head = p1 -> next;
        } else {
            p2 -> next = p1 -> next;
            printf("delete: %d\n", id);
            n = n-1;
        }
    } else {
        printf("%d not been found !\n", id);
    }
}


int display(LIST *head)
{
    int i = 0;
    LIST *p;

    p = head->next;
    printf("Out the id : ");
    while(p != NULL)
    {
        printf(" %d",p -> id);
        i++;
        p = p-> next;
    }
    printf("\n");
    return (i);
}   
void menu(void)
{

    printf("\t\t\n");
    printf("\t\t[A]Inserted the id !\n");
    printf("\t\t[R]Delete the id !\n");
    printf("\t\t[D]Display the id !\n");
    printf("\t\t[Q]The program over !\n");
    printf("\t\t\n");
    printf("\t\t\n");
    printf("\t\tPlease input your choose : A R D Q !\n");
}
int main(void)
{
    int id;
    int choose;
    while(1)
    menu();
    scanf("%d",&choose);
    switch(choose) {
     
        case 'A':
        printf("\nInput the inserted id %d", id);
        scanf("%d",id);
       add_node('A');
        break;
        case 'R':
        printf("\nInput the delete id %d", id);
        scanf("%d",id);
        remove_node('R');
        break;
        case 'D':
        printf("\nInput the display id %d", id);
        scanf("%d",id);
        display('R');
        break;
        case 'Q':
         
        default:printf("ERROR!\n");
    }
     
    return 0;

}
有很多错误,功能也不能实现

 
搜索更多相关主题的帖子: include success 
2005-05-11 14:19
yuanyuan
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-5-11
收藏
得分:0 
等到下次的时候我想我的纳期就过了,哎呀。郁闷

2005-05-11 15:04
yuanyuan
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-5-11
收藏
得分:0 
不能通过啊,所以要请教啊,说实话我对链表真的很头疼,我都把我自己给弄晕了
编制具有下列结构的链表。(使用参考书学习链表的内容)
    typedef struct list_t{
        int id;                  (识别结点的值)
        struct list_t *prev;     (指向前一个结点的指针)
        struct list_t *next;    (指向后一个结点的指针)
    } LIST;
链表的各结点是从表的前头,以id值小到大的顺序链接起来的。
编写在此链表中,增加结点的函数(add_node())和删除结点(remove_node())的函数。
各自的函数式样如下:
void add_node(int id, LIST *p);
功能:・从表的前面起,按顺序比较各结点的id和通过参数指定的id。
                  如发现有比参数指定的id大的id时,在其结点的前面插入指定的结点。
                 ・表中,没有被链接的结点时,在表的前头联接被指定的结点。
                 ・比较id,达到表的最后时,在表的最后联接被指定的结
void remove_node(int id);
功能:从表中删除以参数指定的结点。
并且,使用上述函数,编写下列程序,
首先,选择表操作(Add(追加):A、Remove(删除):R、Display(显示):D、終了(结束):Q)的菜单。
;选择A时,输入将要增加的id,追加到表上,
选择R时,输入将要删除的id,从表中删除。
选择D时,显示表中的所有id.
;选择Q时,程序结束。
进行对于表的上述处理后,再次显示选择表操作的菜单。
尚且,链接表的各结点要通过malloc()函数确保,通过free()函
这是这到题的式样书,请帮忙

2005-05-11 15:15
yuanyuan
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-5-11
收藏
得分:0 
请改正,休整完整

2005-05-11 15:40
快速回复:[求助]
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019004 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved