| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 275 人关注过本帖
标题:删除链表中输入的值
取消只看楼主 加入收藏
烟雾中的迷茫
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:621
专家分:1069
注 册:2011-2-9
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:1 
删除链表中输入的值
程序代码:
#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(struct student)

struct student
{
    float num;
    char name[10];
    char sex[10];
    int age;
    struct student *next;
};

int main()
{

    struct student *delete(int age);
    struct student *creat(void);

    struct student *head;
    int age;

    printf("please input the basic date\n");
    creat();

    printf("please input the age that you want to delege\n");
    scanf("%d",&age);
    head=delete(age);

    printf("follows are the link have delete the age you input\n");
    do
    {
        printf("%f\t%s\t%s\t%d\n",head->num,head->name,head->sex,head->age);
        head=head->next;
    }while(head!=NULL);
return 0;
}

struct student *creat(void)
{
    struct student *head,*p[2];
    int n=0;

    printf("please input the first node date\n");
    head=(struct student *)malloc(LEN);
    scanf("%f%s%s%d",&p[0]->num,p[0]->name,p[0]->sex,&p[0]->age);
    p[0]=head;

    while(p[0]->next!=NULL)
    {
       if(p[0]->num!=0)
        {
            p[1]=p[0];
            printf("please input the %d node\n",++n);
            p[0]=(struct student *)malloc(LEN);
            scanf("%f%s%s%d",&p[0]->num,p[0]->name,p[0]->sex,&p[0]->age);
            p[1]->next=p[0];
        }
        else p[0]->next=NULL;
        p[1]->next=NULL;
    }
  return head;
}

struct student *delete(int age)
{
    struct student *head,*p[2];
    p[0]=creat();
    head=creat();

     while(p[0]->next!=NULL)
     {
         if(p[0]->age==age)
         {
             if(p[0]==head)
                 head=p[0]->next;
            else
                p[1]->next=p[0]->next;
         }
          else  p[1]=p[0]->next;
          p[0]=p[0]->next;
     }
     if(p[0]->next==NULL)
         if(p[0]->age==age)
         head=NULL;
         return head;
}
这个链表编译链接无措 就是在执行时 输入第二个值得时候程序出错 无法执行
首先申明 编译器没问题 麻烦看下 哪出问题了
搜索更多相关主题的帖子: next 
2011-05-26 18:27
烟雾中的迷茫
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:621
专家分:1069
注 册:2011-2-9
收藏
得分:0 
好的谢谢 指教
2011-05-26 22:34
快速回复:删除链表中输入的值
数据加载中...
 
   



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

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