删除链表中输入的值
程序代码:#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;
}
这个链表编译链接无措 就是在执行时 输入第二个值得时候程序出错 无法执行首先申明 编译器没问题 麻烦看下 哪出问题了









