第k小数

来源:互联网 发布:怎么在淘宝上刷销量 编辑:程序博客网 时间:2024/05/15 17:51
int kth_elem(int a[], int low, int high, int k){int pivot = a[low]int low_temp = low;int high_temp = high;while(low < high){while(low < high && a[high]>=pivot)--high;a[low] = a[high]while(low < high && a[low] <= pivot)--low;a[high] = a[low];}a[low] = pivot;if(low ==k)return a[low];else if(low < k)return kth_elem(a,low_temp, low-1,k);else return kth_elem(a,low+1, high_temp,m-k)}

0 0
原创粉丝点击