单链表的建立,求长度,打印

来源:互联网 发布:淘宝上解id靠谱吗 编辑:程序博客网 时间:2024/05/22 12:31
//定义一个单链表typedef struct student{     int data;     struct student *next;}node;node *create(){   node *p,*s,*head;   int x,cycle = 0;   head = (node*)malloc(sizeof(node));   p = head;   while(cycle)   {      printf("please enter your data:\n");      scanf("%d",&x);      if(x!=0)//输入0则结束输入      {         s = (node*)malloc(sizeof(node));         s->data = x;         p->next = s;         p=s;      }              else             {              cycle = 0;             }    }                 head = head ->next;//没有这句头结点中未存放数据      p->next = NULL;     return head;}
原创粉丝点击