C语言创建单链表

上传人:飞****9 文档编号:129222499 上传时间:2020-04-22 格式:DOC 页数:2 大小:14.50KB
返回 下载 相关 举报
C语言创建单链表_第1页
第1页 / 共2页
C语言创建单链表_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

《C语言创建单链表》由会员分享,可在线阅读,更多相关《C语言创建单链表(2页珍藏版)》请在金锄头文库上搜索。

1、#include#include#includestruct nodeint data;struct node *next;struct node *creat()/创建链表struct node *p,*q,*head;int i=1,j;p=head=(struct node *)malloc(sizeof(struct node);printf(请输入第%d个数字,i);scanf(%d,&p-data);head=p;while(p-next!=NULL&p-data!=0)q=(struct node *)malloc(sizeof(struct node);i+;printf(请输

2、入第%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(%dn,p-data);p=p-next;return(head);int main() creat();printf(创建链表n);return 0;void destroy()struct node *r,*s;p=head-next;int i=1; if(p!=NULL) printf(链表为空或不存在n); return ; while(s!=NULL) printf(the %d date is %dn,i,s-date);i=i+1;s=s-next; while(p!=NULL) r=p-next ;free(p);p=r; void main()int a; void creat(int a); void destroy(); printf(输入链表长度_); scanf(%d,&a); creat(a); printf(销毁链表n); / destroy();

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > IT计算机/网络 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号