欢迎来到天天文库
浏览记录
ID:53879028
大小:14.50 KB
页数:2页
时间:2020-04-10
《C语言创建单链表.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#includestructnode{intdata;structnode*next;};structnode*creat()//创建链表{structnode*p,*q,*head;inti=1,j;p=head=(structnode*)malloc(sizeof(structnode));printf("请输入第%d个数字",i);scanf("%d",&p->data);head=p;while(p->next!=NULL&&p->data!=0){q=(structnode*)mal
2、loc(sizeof(structnode));i++;printf("请输入第%d个数字",i);scanf("%d",&q->data);j=q->data;p->next=q;p=q;if(j=0)free(p);}p->next=NULL;p=head;while(p!=NULL){printf("%d",p->data);p=p->next;}return(head);}intmain(){creat();printf("创建链表");return0;}voiddestroy(){structnode*r,*s;p=head->next;inti=1;if(p!=
3、NULL){printf("链表为空或不存在");return;}while(s!=NULL){printf("the%ddateis%d",i,s->date);i=i+1;s=s->next;}while(p!=NULL){r=p->next;free(p);p=r;}}voidmain(){inta;voidcreat(inta);voiddestroy();printf("输入链表长度_");scanf("%d",&a);creat(a);printf("销毁链表");//destroy();}
此文档下载收益归作者所有