标签:nbsp wap turn 效率 == err 数组 笔试 exce
#include<stdlib.h> #include<exception> #include<stdexcept> using namespace std; // Random Partition int RandomInRange(int min,int max) { int random=rand()%(max-min+1)+min; return random; } // 两个数交换 void Swap(int* num1,int* num2) { int temp=*num1; *num1=*num2; *num2=temp; } int Partition(int data[],int length,int start,int end) { logic_error ex("Invalid Parameters"); if(data==nullptr || length<=0 || start<0 || end>=length) throw exception(ex); int index=RandomInRange(start,end); Swap(&data[end],&data[index]); int small=start-1; for(index=start;index<end;++index) { if(data[index]<data[end]) { ++small; if(small!=index) Swap(&data[index],&data[small]); } } ++small; Swap(&data[small],&data[end]); return small; }
标签:nbsp wap turn 效率 == err 数组 笔试 exce
原文地址:http://www.cnblogs.com/DHUtoBUAA/p/7542425.html