int find_K_Largest( int begin, int end, int k ){
int s = begin + 1,t = end,first;
first = arr[b];
while( s < t ){
while( arr[s] < first && s < t )
s ++;
while( arr[t] >= first && s < t )
t --;
int tmp;
tmp = arr[s];
arr[s] = arr[t];
arr[t] = tmp;
}
if( arr[t] > first )
t --;
arr[b] = arr[t];
arr[t] = first;
if( t - begin + 1 == k )
return first;
else if( t - begin + 1 > k )
return partion( begin, t - 1, k );
else
return partion( t + 1, end, k - ( t - begin + 1 ) );
}
寻找第K大的数
最新推荐文章于 2022-09-19 18:39:29 发布