标题:怎样创建一个链表
取消只看楼主
浅暗花璃
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2016-3-31
结帖率:77.78%
已结贴  问题点数:6 回复次数:0 
怎样创建一个链表
怎样创建一个链表
struct student *create()
{
    struct student *head,*p1,*p2;
    int i=0,n;
    head=NULL;
    printf("plaese input n:");
    scanf("%d",&n);
    p1=((struct student *)malloc(sizeof(struct student)));
    p2=((struct student *)malloc(sizeof(struct student)));
    scanf("%d",&p1->num);
     //scanf("%s",p1->name);
     //fflush(stdin);
    // printf("plase input sex,f-女,m-男:");
    // scanf("%c",&p1->sex);
     //fflush(stdin);
     //scanf("%d",&p1->old);
    for(i=0;i<n;i++)
    {   
        if(i==0)
            head=p1;
        else{
             p1->next=NULL;
            p2->next=p1;
            p2=p1;
        }
   p1=(struct student *)malloc(sizeof(struct student));

    scanf("%d",&p1->num);
   }
  
   
    free(p1);
    return(head);

    }
搜索更多相关主题的帖子: create 
2016-06-02 19:45



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-465527-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014261 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved