欢迎来到天天文库
浏览记录
ID:58536074
大小:13.00 KB
页数:2页
时间:2020-09-03
《数据结构C语言单链表建立、输出、倒置、倒置输出.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#defineNULL0structnode{intnum;structnode*next;};voidmain(){inti;structnode*L,*s,*p,*h,*q,*k;L=(node*)malloc(sizeof(structnode));//L->num=NULL;p=L;printf("请输入");for(i=0;i<6;i++){s=(node*)malloc(sizeof(structnode));scanf("
2、%d",&s->num);p->next=s;p=s;}p->next=NULL;//以上为链表的建立和输入//以下为元素的交换p=L;while(p->next->num!=20)p=p->next;h=p->next;p->next=p->next->next;h->next=p->next->next;p->next->next=h;p->next->next->next=h->next;//free(h);//以下为链表的输出p=L->next;printf("交换后输出");while(p!=N
3、ULL){printf("%d",p->num);p=p->next;}//以下为链表的倒置p=L;while(p->next->next!=NULL)p=p->next;q=p->next;q->next=p;p->next=NULL;p=L;for(i=0;i<4;i++){while(p->next->next!=NULL)p=p->next;k=p->next;k->next=p;p->next=NULL;p=L;}L->next=q;//倒置后链表的输出p=L->next;printf("倒置后
4、输出");while(p!=NULL){printf("%d",p->num);p=p->next;}}
此文档下载收益归作者所有