欢迎来到天天文库
浏览记录
ID:57687283
大小:40.00 KB
页数:2页
时间:2020-09-01
《c语言实现冒泡排序加二分查找法.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#define_CRT_SECURE_NO_WARNINGS#include#include#includevoidmaopao(intb[],intn){inttem;for(inti=0;ib[j+1]){tem=b[j];b[j]=b[j+1];b[j+1]=tem;}}}printf("冒泡排序");for(intk=0;k2、tsearch2(inta[],intn,intnum){intlow=0,high=n-1,mid=(low+high)/2;while(low<=high){if(num==a[mid]){returnmid;}elseif(a[mid]>num){high=mid-1;mid=(low+high)/2;}else{low=mid+1;mid=(low+high)/2;}}return-1;}voidmain(){inta[10];time_ttms;srand((unsignedint)time(&tms));for(i3、nti=0;i<10;i++){a[i]=rand()%100;printf("%d",a[i]);}maopao(a,10);intab;printf("请输入要查找的数据");scanf("%d",&ab);intx=search2(a,10,ab);if(x==-1)printf("没有找到哦");elseprintf("位置是%d",x);system("pause");}
2、tsearch2(inta[],intn,intnum){intlow=0,high=n-1,mid=(low+high)/2;while(low<=high){if(num==a[mid]){returnmid;}elseif(a[mid]>num){high=mid-1;mid=(low+high)/2;}else{low=mid+1;mid=(low+high)/2;}}return-1;}voidmain(){inta[10];time_ttms;srand((unsignedint)time(&tms));for(i
3、nti=0;i<10;i++){a[i]=rand()%100;printf("%d",a[i]);}maopao(a,10);intab;printf("请输入要查找的数据");scanf("%d",&ab);intx=search2(a,10,ab);if(x==-1)printf("没有找到哦");elseprintf("位置是%d",x);system("pause");}
此文档下载收益归作者所有