快排查找第K小的數
#include "iostream.h"
using namespace std;
int findMedian(int *A,int left,int right){
int center = (left+right)/2;
if(A[left]>A[center]){
swap(A[left],A[center]);
}
if(A[left]>A[right]){
swap(A[left],A[right]);
}
if(A[center]>A[right]){
swap(A[center],A[right]);
}
//A[right]已經大於A[center]
swap(A[center],A[right-1]);
return A[right-1];
}
void insertSort(int *A, int left,int right){
for(int i=left+1;i<=right;i++){
int p = A[i];
int j;
for( j=i;j>=left&&A[j-1]>p;j--){
A[j]=A[j-1];
}
A[j]=p;
}
}
#define CUTOFF 5
int qselect(int *A, int k, int left,int right){
if(left+CUTOFFpivot){}
if(i=pivot&&A[j]<=pivot,交換二者位置
swap(A[i],A[j]);
}else
break;
}
swap(A[i],A[right-1]);
int t = i-left+1;
if(k==t)
return A[i];
else if(k>N;
for(int i=0;i>A[i];
}
int k;
cin>>k;
if(k<=N-0)
cout<