C链表回顾

来源:互联网 发布:移动定制机网络解锁 编辑:程序博客网 时间:2024/05/19 20:56
 #define TYPE struct stu
    #define LEN sizeof (struct stu)
    struct stu
        {
          int num;
          int age;
          struct stu *next;
        };
    TYPE *creat(int n)
    {
        struct stu *head,*pf,*pb;
        int i;
        for(i=0;i<n;i++)
        {    
          pb=(TYPE*) malloc(LEN);
          printf("input Number and  Age\n");
          scanf("%d%d",&pb->num,&pb->age);
          if(i==0)
          pf=head=pb;
          else pf->next=pb;
          pb->next=NULL;
          pf=pb;
        }
        return(head);
    }
    void main()
    {
        struct stu *head = NULL;
        int n = 0;
        scanf("%d", &n);
        head = creat(n);
    }
这样应该可以了。
原创粉丝点击