RandomizedSelect.h:
#includenamespace dksl{ /* *交换 */ void Swap(int* numArray,int swapFrom,int swapTo) { int temp=numArray[swapFrom]; numArray[swapFrom]=numArray[swapTo]; numArray[swapTo]=temp; } /* *随机化快排 */ int RandomizedPartition(int* numArray,int head,int tail) { int r=rand()%(tail-head+1)+head; Swap(numArray,r,tail); int pivot=numArray[tail]; int i=head-1; int j=tail; while(true) { do { i++; }while (i<=tail&&numArray[i] =head&&numArray[j]>pivot); if(j
RandomizedSelect.cpp
// RandomizedSelect.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include#include "RandomizedSelect.h"using namespace std;using namespace dksl;int _tmain(int argc, _TCHAR* argv[]){ int a[10] = { 1, 4, 8, 15, 10, 25, 54, 15, 12, 2}; cout< <