实现循环单链表表各种基本运算算法.docVIP

  • 29
  • 0
  • 约5.13千字
  • 约 5页
  • 2017-06-25 发布于湖北
  • 举报

实现循环单链表表各种基本运算算法.doc

实验目的:题目: #include stdio.h #include conio.h #include stdlib.h #include windows.h struct node { char c; struct node *next; }; struct node *head,*tail,*p,*q,*r; int cut1=0; void show() { printf(\n\n\t\t\t\t欢 迎 使 用!); printf(\n\n\t\t\t1、加入元素); printf(\n\n\t\t\t2、输出全部元素和元素个数); printf(\n\n\t\t\t3、输出特定元素位置); printf(\n\n\t\t\t4、输出特定位置元素); printf(\n\n\t\t\t5、在特定位置插入元素); printf(\n\n\t\t\t6、删除特定位置元素); printf(\n\n\t\t\t7、删除全部元素); printf(\n\n\t\t\t0、退出); printf(\n\n\t\t请输入:); } void chu() { head=(struct node*)malloc(sizeof(struct node)); head-next=NULL; tail=head; } void add() { int n,i; printf(\t\t\t请输入要加入的元素个数:); scanf(%d,n); for(i=0; in; i++) { fflush(stdin); p=(struct node*)malloc(sizeof(struct node)); printf(\t\t\t请输入元素(单个字母),按回车结束:); scanf(%c,p-c); tail-next=p; p-next=NULL; tail=p; cut1++; } printf(\n\n\t\t加入完成,按任意键返回主菜单!); getch(); } void _count() { int cut=1; if(head-next==NULL) { printf(\n\n\n\n\n\n\t\t没有元素 ,按任意键返回主菜单!\n\n\n\n\n\n); getch(); return ; } p=head-next; while(p-next) { printf(%c-,p-c); cut++; p=p-next; } printf(%c\n,p-c); printf(\t共 有 %d 个 元 素。,cut); printf(\n\n\t\t输出完成,按任意键返回主菜单!); getch(); } void show1() { char s; int cut=0; fflush(stdin); printf(请输入要查找的元素:); scanf(%c,s); p=head-next; while(p) { cut++; if(p-c==s) { printf(\n\t\t此元素位于链表第%d的位置!,cut); printf(\n\n\t\t输出完成,按任意键返回主菜单!); getch(); return ; } p=p-next; } printf(\n\t\t没有找到该元素!); printf(\n\n\t\t输出完成,按任意键返回主菜单!); getch(); } void show2() { int cut=0,t; printf(请输入你要找的是第几个元素:); scanf(%d,t); if(tcut1) { printf(\n\t\t没有找到该元素!); printf(\n\n\t\t输出完成,按任意键返回主菜单!); getch(); retu

文档评论(0)

1亿VIP精品文档

相关文档