资源预览内容
第1页 / 共2页
第2页 / 共2页
亲,该文档总共2页全部预览完了,如果喜欢就下载吧!
资源描述
#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(请输入第%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();
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号