int findKth(int * begin, unsigned int length, unsigned int k)
{
int *i, *m;
int *l = begin;
while (length >= 1)
{
m = l;
for (i = l + 1; i < l + length; i++)
{
if (*i < *l)
{
swap(m, i);
}
}
swap(m,l);
if(m == begin + k-1 )
{ return *m;}
else if (m < begin + k-1)
{
length = length - (m+1-l );
l = m+1;
}
else if(m > begin + k-1)
{
length = (m-1-l+1);
}
}
return *m;
}
阅读(1824) | 评论(0) | 转发(0) |