#include<iostream>
#include<ctime>
using namespace std;
int Partition(int A[], int low, int high);
int Selection(int A[], int low, int high, int k)
{
int pivot_key, pivot;
int l,h;
while(low <= high)
{
l = low;
h = high;
pivot_key = A[l];
while(l < h)
{
while(l < h && A[h] >= pivot_key) --h;
A[l] = A[h];
while(l < h && A[l] <= pivot_key) ++l;
A[h] = A[l];
}
A[l] = pivot_key;
pivot = l;
if(k == pivot+1)
{
return A[pivot];
}
else if(k > pivot+1)
{
low = pivot + 1;
}
else
{
high = pivot - 1;
}
}
cout<<"k超出界线!"<<endl;
return -1;
}
int Partition(int A[], int low, int high)
{
int pivot_key = A[low];
while(low < high)
{
while(low < high && A[high] >= pivot_key) --high;
A[low] = A[high];
while(low < high && A[low] <= pivot_key) ++low;
A[high] = A[low];
}
A[low] = pivot_key;
return low;
}
int main()
{
long const N = 10;
int A[N] = {3,2,5,6,8,9,1,0,4,7};
for(int i=0; i<N; i++)
{
cout<<Selection(A,0,9,i+1);
}
cout<<endl;
return 0;
}