void InputHandler::calculateSortTime() {
	Sorter<double> s;
	time_t b1;
	s.quickSort(qsa, numDoubles);
	time_t a1;

	time_t b2;
	s.insertionSort(isa, numDoubles);
	time_t a2;

	time_t b3;
	s.oddEvenSort(msa, numDoubles);
	time_t a3;

	cout<<endl;
	cout<<"QuickSort"<<endl;
	cout<<"Time started: "<<b1<<endl;
	cout<<"Time ended: "<<a1<<endl;
	cout<<"Time difference: "<<-(double)difftime(a1, b1)<<endl;
	cout<<endl;

	cout<<"Insertion Sort"<<endl;
	cout<<"Time started: "<<b2<<endl;
	cout<<"Time ended: "<<a2<<endl;
	cout<<"Time difference: "<<-(double)difftime(a2, b2)<<endl;
	cout<<endl;

	cout<<"Odd Even Sort"<<endl;
	cout<<"Time started: "<<b3<<endl;
	cout<<"Time ended: "<<a3<<endl;
	cout<<"Time difference: "<<-(double)difftime(a3, b3)<<endl;
	cout<<endl;
}
예제 #2
0
파일: sorts.cpp 프로젝트: alyssaq/sorting
int main() {
  int myints[] = {16,277,3,-2,24,-54,-1,0,56,87,7,-7};
  vector<int> items (myints, myints + sizeof(myints) / sizeof(int));
  const string sortedStr = "-54, -7, -2, -1, 0, 3, 7, 16, 24, 56, 87, 277";
  int myints2[] = {0,4,6,1,9,3,6,2,8,4,3,1};
  vector<int> items2 (myints2, myints2 + sizeof(myints2) / sizeof(int));
  const string sortedStr2 = "0, 1, 1, 2, 3, 3, 4, 4, 6, 6, 8, 9";
  int myints3[] = {0,4,2391,72,111,3,6,72,2,85,44,3,991,1};
  vector<int> items3 (myints3, myints3 + sizeof(myints3) / sizeof(int));
  const string sortedStr3 = "0, 1, 2, 3, 3, 4, 6, 44, 72, 72, 85, 111, 991, 2391";
  cout << "Input: " << vector2string(items) << endl;
  cout << "Input: " << vector2string(items2) << endl;

  Sorter sorter;
  vector<int> sortedItems(items);
  sorter.insertionSort(sortedItems);
  assertAndPrint(sortedItems, sortedStr, "insertionSort");

  sortedItems = items;
  sorter.selectionSort(sortedItems);
  assertAndPrint(sortedItems, sortedStr, "selectionSort");

  sortedItems = items;
  sorter.bubbleSort(sortedItems);
  assertAndPrint(sortedItems, sortedStr, "bubbleSort");

  sortedItems = items;
  sorter.mergeSort(sortedItems);
  assertAndPrint(sortedItems, sortedStr, "mergeSort");

  sortedItems = items;
  sorter.quickSort(sortedItems);
  assertAndPrint(sortedItems, sortedStr, "quickSort");

  sortedItems = items2;
  sorter.countingSort(sortedItems);
  assertAndPrint(sortedItems, sortedStr2, "countingSort");

  sortedItems = items3;
  sorter.radixSort(sortedItems);
  assertAndPrint(sortedItems, sortedStr3, "radixSort");
}