电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

钟晓鸿单循环链表基本操作VIP免费

钟晓鸿单循环链表基本操作_第1页
1/5
钟晓鸿单循环链表基本操作_第2页
2/5
钟晓鸿单循环链表基本操作_第3页
3/5
#include#includetypedefstructnode{intdata;structnode*next;}lnode,*linkedlist;/*单循环链表建立*/linkedlistlinkedlistcreat(){intx;linkedlistL,p,r;L=(lnode*)malloc(sizeof(lnode));L->next=NULL;r=L;scanf("%d",&x);while(x!=-1){p=(lnode*)malloc(sizeof(lnode));p->data=x;r->next=p;r=p;scanf("%d",&x);}r->next=L;returnL;}/*打印链表*/voidlinkedlistprint(linkedlistL){linkedlistp=L->next;printf("\n///////////////////////*打印链表*////////////////////////////\n");while(p!=L){printf("%5d",p->data);p=p->next;}}/*求单循环链表的长度*/voidlinkedlistlenght(linkedlistL){intx=0;linkedlistp=L->next;while(p!=L){x++;p=p->next;}printf("\n//////////////////////////*求单循环链表的长度*///////////////////////////");printf("\n本单循环链表的长度是:%d",x);}/*求第i个元素*/voidlinkedlistget(linkedlistL){intx,j=1;linkedlistp=L->next;printf("\n//////////////////////////*求第i个元素*///////////////////////////\n");printf("\n您要求第几个元素请输入:");scanf("%d",&x);while(jnext;}printf("您要求的第%d个元素是%d",x,p->data);}/*元素定位*/voidlinkedlistlocate(linkedlistL){linkedlistp=L->next;intx,j=1;printf("\n/////////////////////////*元素定位*///////////////////////////\n");printf("您要定位的元素是什么请输入:");scanf("%d",&x);while(p->data!=x){j++;p=p->next;}printf("您要定位的元素%d是本单循环链表中的第%d个元素",x,j);}/*求某元素前驱*/voidlinkedlistprior(linkedlistL){linkedlistpre=L,p=L->next;intx;printf("\n////////////////////////////*求某元素前驱*////////////////////////////\n");printf("\n您要用于求其前驱的元素是请输入:");scanf("%d",&x);if(p->data==x)printf("\n%d就是本单循环链表的第一个元素,故其没有前驱。",x);else{while(p->data!=x){pre=pre->next;p=p->next;}printf("\n您输入的元素%d的前驱是%d",x,pre->data);}}/*求某元素后继*/voidlinkedlistnext(linkedlistL){intx;linkedlistp=L->next;printf("\n////////////////////////////*求某元素后继*////////////////////////////\n");printf("\n您要求哪个元素的后继请输入:");scanf("%d",&x);while(p->data!=x){p=p->next;}if(p->next==L)printf("\n%d是本单循环链表规定的最后一个值。",x);elseprintf("\n%d的后继是%d",x,p->next->data);}/*在某元素后插入的函数*/voidlinkedlistinser(linkedlistL){intx,y;linkedlists,q=L->next,p=L->next;printf("\n/////////////////////////////*在某元素后插入的函数*/////////////////////////////\n");printf("您要在哪个元素后插入什么元素请分别输入:");scanf("%d%d",&x,&y);s=(lnode*)malloc(sizeof(lnode));s->data=y;while(p->data!=x){p=p->next;}s->next=p->next;p->next=s;}/*删除元素函数*/voidlinkedlistdelete(linkedlistL){intx;linkedlistpre=L,p=L->next;printf("\n//////////////////////////////*删除元素函数*//////////////////////////////\n");printf("\n您要删除哪个元素请输入:");scanf("%d",&x);while(p->data!=x){pre=pre->next;p=p->next;}pre->next=p->next;free(p);}voidmain(){intflag;linkedlistp;printf("\n请您输入数据构造单循环链表:");p=linkedlistcreat();printf("\n///////////////////////////请您选择操作类型///////////////////////////\n");printf("0.退出操作。1.打印链表。2.求链表长度。3.求第i个元素。4.元素定位。5.求某元素前驱。6.求某元素后继。7.在某元素后插入的函数。8.删除元素函数。\n");printf("\n请选择:");scanf("%d",&flag);while(flag){switch(flag){case0:break;/*退出操作*/case1:linkedlistprint(p);break;/*打印链表*/case2:linkedlistlenght(p);break;/*求单循环链表的长度*/case3:linkedlistget(p);break;/*求第i个元素*/case4:linkedlistlocate(p);break;/*元素定位*/case5:linkedlistprior(p);break;/*求某元素前驱*/case6:linkedlistnext(p);break;/*求某元素后继*/case7:linkedlistinser(p);break;/*在某元素后插入的函数*/case8:linkedlistdelete(p);break;/*删除元素函数*/}printf("\n请选择:");scanf("%d",&flag);}printf("\n退出操作。");}

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

钟晓鸿单循环链表基本操作

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部