C语言二分法

来源:互联网 发布:linux ssh目录 编辑:程序博客网 时间:2024/04/28 15:21
(uint)mid); printf("/n"); find = 1; //找到元素 } else if(x < t[mid]) bot = mid-1; //指定的元素在前半部分 else if(x > t[mid]) top = mid+1; //指定的元素在后半部分 } while((top <= bot) && (find == 0)); //直到查找次数完成 if(find == 0) printf("%3d not been found." (uint)x it is t[%d]" find; //指向数列的中间、开头、未尾、 top = 0; // bot = n-1; find = 0; do { mid = (top+bot)/2; if(x == t[mid]) { printf("find:%3d bot top uchar x){ uchar mid uchar n void search(uchar t[] 再在两边各自选取轴值再按前面排序 比轴值大的放到右边 比较时把所有比轴值小的放到轴值的左边 (uint)x); //输出没有找到指定元素 printf("/n");} |||快速排序法就是二分法的应用快速排序是先找到一个轴值 直到完成