中南大学数据结构实验报告资料.docVIP

  • 17
  • 0
  • 约1.21千字
  • 约 23页
  • 2016-08-29 发布于湖北
  • 举报
数据结构实验报告 专业班级: 指导老师:余腊生 姓 名: 学 号: 实验一 单链表的基本操作的实现 一、实验目的 掌握单链表的基本操作:插入、删除、查找等运算。 利用线性表的特性以及其链式存储结构特点对线性表进行相关操作。 四、 实验内容 程序中演示了单链表的创建、插入、删除和查找。 程序如下: #includestdio.h #define N 21 void main(void) { int a[N]; int i,n,num; int top,bottom,mid; int flag=1; int loc=-1; printf(你想在多少个数中进行折半查找,请输入(1--20):); scanf(%d,n); while(n1||n20) { printf(你输入的数不正确,请重新输入:\n); printf(你想在多少个数中进行折半查找,请输入(1--20):); scanf(%d,n); } printf(请你输入一个整数a[1]:); scanf(%d,a[1]); i=2; while(i=n) { printf(请你输入一个整数a[%d]:,i); scanf(%d,a[i]); i++; } printf(\n输出表列\n); for(i=1;i=n;i++) { printf(%6d,a[i]); } printf(\n); printf(请你输入要查找的数:); scanf(%d,num); flag=1; top=n; bottom=1; mid=(top+bottom)/2; while(flag) { printf(top=%d, bottom=%d, mid=%d,a[i]=%d\n,top,bottom,mid,mid,a[mid]); if((numa[top])||(numa[bottom])) { loc=-1; flag=0; } else if(a[mid]==num) { loc=mid; printf(找到数 %6d的位置%2d\n,num,loc); break; } else if(a[mid]num) { top=mid-1; mid=(top+bottom)/2; } else if(a[mid]num) { bottom=mid+1; mid=(top+bottom)/2; } } if(loc==-1) { printf(%d这个数在表列中没有找到。\n,num); } } 运行结果如下:

文档评论(0)

1亿VIP精品文档

相关文档