#include <iostream>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#define LEN 10000000
int arr[LEN];
using namespace std;
int partion(int a[],int p,int r){
//rand
srand((unsigned)time( NULL));
int e=rand()%(r-p+1)+p;
int tem;
tem=a[e];
a[e]=a[r];
a[r]=tem;
int x=a[r], i=p-1;
for (int j=p;j<r;j++){
if (a[j]>=x){
tem=a[i+1];
a[i+1]=a[j];
a[j]=tem;
i++;
}
}
tem=a[r];
a[r]=a[i+1];
a[i+1]=tem;
return i+1;
}
void quicks(int a[],int p,int r){
if (p<r){
int q=partion(a,p,r);
quicks(a,p,q-1);
quicks(a,q+1,r);
}
}
int main()
{
srand((unsigned)time(NULL));
for(int i=0; i<LEN; i++)
{
arr[i]=rand();
}
clock_t t1=clock();
quicks(arr,0,LEN);
clock_t t2=clock();
cout<<"recurcive "<<1.0*(t2-t1)/CLOCKS_PER_SEC<<endl;
cout<<"Finished!"<<endl;
return 0;
}