学生信息是:姓名,学号,性别,年龄,用一个链表,把这些信息连在一起,给出一个age, 在些链表中删除学生年龄等于age的学生信息。

http://blog.csdn.net/dahai_881222/article/details/7873463


typedef struct stu
{
    char name[20];
    char sex;
    int no;
    int age;
    struct stu * next;
}node;

node *create(int n)
{
 int i;
 node *head,*p ,*s ,*s1;
 head = (node*)malloc(sizeof(node));
 head->next = NULL;
 p = head;
 
 while(n)
 {
  s = (node*)malloc(sizeof(node));
  p->next = s;
  printf("请输入每个人的信息:姓名 性别 学号 年龄 ");
  scanf("%s %c %d %d",s->name ,&s->sex ,&s->no,&s->age);
  s->next = NULL;
  p = s;
  n--;
 }
 return head;
}

 

void del(node *head , int a)
{
   node *p,*s,*str;
   p = head;
   while(p != NULL)
   {   
     s = p;
        p = p->next;
    if( p->age == a )
    {
          s->next = p->next;
    break;
    }
   }
}

void display(node *head)
{
 node *p;
 p = head->next;
 while(p != NULL)
 {
  printf("%s %c %d %d",p->name ,p->sex ,p->no ,p->age);
  p = p->next;
 }
}

void main()
{
 node *head;
 int n;
 printf("请输入创建的个数:");
 scanf("%d",&n);
 head = create(n);
 display(head);
 int age;
 printf("请输入删除的年龄:");
 scanf("%d",&age);
 del(head , age);
 display(head);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值