#include<stdio.h>
#include<alloc.h>
#define NULL 0
#define len sizeof(struct student)
struct date
{
int year,month,day;
};
struct student
{
long num;
char name[20];
char sex;
struct date age;
struct student *next;
};
int n;
struct student *creat(void)
{
struct student *p,*head;
head=NULL;
p=(struct student *)malloc(len);
printf("please input information:/n/n");
printf("num:");
scanf("%ld",&p->num);
printf("name:");
scanf("%s",p->name);
getchar();
printf("sex:");
p->sex=getchar();
printf("age:");
scanf("%d%d%d",&p->age.year,&p->age.month,&p->age.day);
if(p->num!=-1)
{head=p;p->next=NULL;}
while(p->num!=-1)
{n++;
p=(struct student *)malloc(len);
printf("please input information:/n/n");
printf("num:");
scanf("%ld",&p->num);
printf("name:");
scanf("%s",p->name);
getchar();
printf("sex:");
p->sex=getchar();
printf("age:");
scanf("%d%d%d",&p->age.year,&p->age.month,&p->age.day);
if(p->num!=-1)
{
p->next=head;
head=p;
}
}
return (head);
}
void print(struct student *p)
{
if(p->next!=NULL)
do
{
printf("The result is: num:%ld name:%s sex:%c age:%d %d %d/n",p->num,p->name,p->sex,p->age.year,p->age.month,p->age.day);
p=p->next;
}while(p!=NULL);
}
struct student *del(struct student *head,long num)
{
struct student *p1,*p2;
if(head==NULL)printf("/nList NULL!/n");
p1=head;
while(num!=p1->num&&p1->next!=NULL&&head!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
{
if(p1==head)head=p1->next;
else p2->next=p1->next;
printf("have del./n");
n--;
}
else printf("Not found!/n");
return head;
}
void main()
{
struct student *stud;
long num;
clrscr();
stud=creat();
print(stud);
printf("Input a num to del:/n");
scanf("%ld",&num);
stud=del(stud,num);
print(stud);
}