欢迎来到天天文库
浏览记录
ID:47847590
大小:81.00 KB
页数:11页
时间:2019-11-26
《查找排序总结》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、总结:几种常见的查找算法^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^^1^//静态查找——顺序查找^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x^x斗、斗、斗、斗、斗、斗、斗、斗、
2、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、斗、^
3、S^y%^
4、S^y%^
5、S^y%^
6、S^
7、S〃静态查找一一索引顺序表,效果比顺序表查找较好,但远不及折半查找^l>^l>^l>^l>^l>^l>^l>吓J〃静态查找一一折半查找#include"stdio.h"^defineSIZE11intBsearch(intnum[SIZE],intnumber,int1ow,inthigh){i
8、ntmid;while(low<=high){mid二(1ow+high)/2;if(number二二num[mid])returnmid;elseif(number>num[mid])low=mid+l;elsehigh=mid-l;}return0;}main(){intnum[SIZE],number,index,i;for(i=l;i9、x=0)printf(,znotfind!");elseprintf(/,location:%d,z,index);getchO;}■!"■!"■!"■!"■!"■!"■!"■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“rjrJrJ夕iJrJ"T**7・^10、lx^lx^lx^lx^lx^lxvx〃静态查找一一次优查找树^include"stdio.h〃#inelude"stdlib.h〃Jtincludez,math・h〃#include"conio.h"^defineSIZE11structNode{intnum;intweight;structNode*lchild,*rchild;};typedefstruct{intnum[S!ZE];intweight[SIZE];}NUM;Pratition(NUM*array,intlow,inthigh){array->num[0]=array->num[low];array->we11、ight[0]=array->weight[low];whi1e(lowarray-〉num[0])--high;{array->num[low]=array->num[high];arrav_>weight[1ow]二array->weight[high];}while(1ownum[high]=array->num[low];arrav_>weight[high]二array->weight[112、ow];}}array->num[low]=array->num[0];array->weight[low]=array->weight[0];returnlow;}Sort(NUM^array,intlow,inthigh){intmid;if(1ow
9、x=0)printf(,znotfind!");elseprintf(/,location:%d,z,index);getchO;}■!"■!"■!"■!"■!"■!"■!"■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“■!“rjrJrJ夕iJrJ"T**7・^
10、lx^lx^lx^lx^lx^lxvx〃静态查找一一次优查找树^include"stdio.h〃#inelude"stdlib.h〃Jtincludez,math・h〃#include"conio.h"^defineSIZE11structNode{intnum;intweight;structNode*lchild,*rchild;};typedefstruct{intnum[S!ZE];intweight[SIZE];}NUM;Pratition(NUM*array,intlow,inthigh){array->num[0]=array->num[low];array->we
11、ight[0]=array->weight[low];whi1e(lowarray-〉num[0])--high;{array->num[low]=array->num[high];arrav_>weight[1ow]二array->weight[high];}while(1ownum[high]=array->num[low];arrav_>weight[high]二array->weight[1
12、ow];}}array->num[low]=array->num[0];array->weight[low]=array->weight[0];returnlow;}Sort(NUM^array,intlow,inthigh){intmid;if(1ow
此文档下载收益归作者所有