#include<stdio.h>
#include<malloc.h>
#define N 5
#define LEN sizeof(struct student)
struct student
{
char num[6];
char name[8];
char sex[2];
int age;
//char kemu[14];
//float score;
struct student *next;
}stu[N];
void main()
{
struct student *p,*pt,*head;
int i,length,iage,flag=1;
int find=0;
while(flag==1)
{
printf("Please input length of list(<10):");
scanf("%d",&length);
if(length<10)
flag=0;
}
for( i=0; i<length; i++ )
{
p=(struct student *)malloc(LEN);
if(i==0)
head=pt=p;
else
pt->next=p;
pt=p;
printf("No:");
scanf("%s",p->num);
printf("Name:");
scanf("%s",p->name);
printf("Sex:");
scanf("%s",p->sex);
printf("Age:");
scanf("%d",&p->age);
}
p->next=NULL;
p=head;
printf("\nNo\tName\tSex\tAge\n");
while(p!=NULL)
{
printf("%4s%8s%6s%6d\n",p->num,p->name,p->sex,p->age);
p=p->next;
}
printf("Please input age:\t");
scanf("%d",&iage);
pt=head;
p=pt;
if(pt->age==iage)
{
p=pt->next;
head=pt=p;
find=1;
}
else
pt=pt->next;
while(pt!=NULL)
{
if(pt->age==iage)
{
p->next=pt->next;
find=1;
}
else
p=pt;
pt=pt->next;
}
if(!find)
printf("Sorry! No find%d",iage);
p=head;
printf("\nNo\tName\tSex\tAge\n");
while(p!=NULL)
{
printf("%4s%8s%6s%6d\n",p->num,p->name,p->sex,p->age);
p=p->next;
}
}
着我做的链表!
跟你的差不多!
你参考一下!