void randomizedQuickSort(vectoru32& v, u32 p, u32 r) {
  if ( p < r ) {
    u32 q = randomizedPartition(v, p, r);
    if (q != 0)
      randomizedQuickSort(v, p, q - 1);
    randomizedQuickSort(v, q + 1, r);
  }
}
示例#2
0
__declspec(dllexport) void randomizedQuickSort(int qarr[], int low, int high)
{
	try 
	{
		if (low < high)
		{
			int pi = randomPartition(qarr, low, high);
			randomizedQuickSort(qarr, low, pi-1);
			randomizedQuickSort(qarr, pi + 1, high);
		}
	}
		catch(...)
		{
			throw "Some exception thrown";
		}
}
int main (int argc, char *argv[]) {

  double tis;
  u32 size = atoi(argv[1]);
  vectoru32 v;
  //srand(wtime());
  generateRandomVector(size, v);

#ifdef DEBUG
  std::cout << "Unsorted vector\n";
  printVector(v);
#endif

  tis = wtime();
  randomizedQuickSort(v, 0, v.size() - 1);
  tis = wtime() - tis;

#ifdef DEBUG
  std::cout << "\nSorted vector\n";
  printVector(v);
#endif

  printf("%lu %.6f\n", v.size(), tis);  
  return 0;
}