Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <chrono>
  4. #include <algorithm>
  5. #include <utility>
  6. #include "sorterhelper.h"
  7. #include "sorter.h"
  8. using namespace std;
  9. using namespace std::chrono;
  10.  
  11. SorterHelper::SorterHelper(){}
  12.  
  13. void SorterHelper::MysteryClassA(vector<int>&myVector)
  14. {
  15. Sorter<int>*mySort = new MysterySorterA<int>;
  16. mySort->setData(myVector);
  17.  
  18. auto startA = high_resolution_clock::now();
  19. mySort->sort();
  20. auto stopA = high_resolution_clock::now();
  21.  
  22. std::chrono::duration<double, std::micro> durationA = stopA - startA;
  23. findTimeA(durationA.count());
  24.  
  25. runtimes.push_back(durationA.count());
  26. originalIndex.push_back(0);
  27.  
  28. delete mySort;
  29. }
  30.  
  31. void SorterHelper::MysteryClassB(vector<int>&myVector)
  32. {
  33. Sorter<int>*mySort = new MysterySorterB<int>;
  34. mySort->setData(myVector);
  35.  
  36. auto startB = high_resolution_clock::now();
  37. mySort->sort();
  38. auto stopB = high_resolution_clock::now();
  39.  
  40. std::chrono::duration<double, std::micro> durationB = stopB - startB;
  41. findTimeB(durationB.count());
  42. runtimes.push_back(durationB.count());
  43. originalIndex.push_back(1);
  44.  
  45. delete mySort;
  46. }
  47.  
  48. void SorterHelper::MysteryClassC(vector<int>&myVector)
  49. {
  50. Sorter<int>*mySort = new MysterySorterC<int>;
  51. mySort->setData(myVector);
  52.  
  53. auto startC = high_resolution_clock::now();
  54. mySort->sort();
  55. auto stopC = high_resolution_clock::now();
  56.  
  57. std::chrono::duration<double, std::micro> durationC = stopC - startC;
  58. findTimeC(durationC.count());
  59. runtimes.push_back(durationC.count());
  60. originalIndex.push_back(2);
  61.  
  62. delete mySort;
  63. }
  64.  
  65. void SorterHelper::MysteryClassD(vector<int>&myVector)
  66. {
  67. Sorter<int>*mySort = new MysterySorterD<int>;
  68. mySort->setData(myVector);
  69.  
  70. auto startD = high_resolution_clock::now();
  71. mySort->sort();
  72. auto stopD = high_resolution_clock::now();
  73.  
  74. std::chrono::duration<double, std::micro> durationD = stopD - startD;
  75. findTimeD(durationD.count());
  76. runtimes.push_back(durationD.count());
  77. originalIndex.push_back(3);
  78.  
  79. delete mySort;
  80. }
  81.  
  82. void SorterHelper::MysteryClassE(vector<int>&myVector)
  83. {
  84. Sorter<int>*mySort = new MysterySorterE<int>;
  85. mySort->setData(myVector);
  86.  
  87. auto startE = high_resolution_clock::now();
  88. mySort->sort();
  89. auto stopE = high_resolution_clock::now();
  90.  
  91. std::chrono::duration<double, std::micro> durationE = stopE - startE;
  92. findTimeE(durationE.count());
  93. runtimes.push_back(durationE.count());
  94. originalIndex.push_back(4);
  95.  
  96. delete mySort;
  97. }
  98.  
  99. void SorterHelper::findTimeA(double durationA)
  100. {
  101. //cout << "MysteryClassA duration: " << durationA << endl;
  102. }
  103.  
  104. void SorterHelper::findTimeB(double durationB)
  105. {
  106. //cout << "MysteryClassB duration: " << durationB << endl;
  107. }
  108.  
  109. void SorterHelper::findTimeC(double durationC)
  110. {
  111. //cout << "MysteryClassC duration: " << durationC << endl;
  112. }
  113.  
  114. void SorterHelper::findTimeD(double durationD)
  115. {
  116. //cout << "MysteryClassD duration: " << durationD << endl;
  117. }
  118.  
  119. void SorterHelper::findTimeE(double durationE)
  120. {
  121. //cout << "MysteryClassE duration: " << durationE << endl;
  122. //cout << endl;
  123. }
  124.  
  125. void SorterHelper::determineSort()
  126. {
  127. vector<pair<double, int>>match;
  128. string sort1, sort2, sort3, sort4, sort5;
  129.  
  130. for(int i = 0; i < 5; i++)
  131. {
  132. match.push_back(make_pair(runtimes[i],originalIndex[i]));
  133. cout << match[i].first << "\t" << match[i].second << endl;
  134. }
  135.  
  136. sort(match.begin(),match.end());
  137.  
  138. cout << endl;
  139. for(int i = 0; i < 5; i++)
  140. {
  141. cout << match[i].first << "\t" << match[i].second << "\t" <<i<< endl;
  142. }
  143.  
  144. cout << endl;
  145.  
  146. for(int i = 0; i < 5; i++)
  147. {
  148. if(i==0){
  149. cout << "MysterySortA is ";
  150. }
  151.  
  152. if(i==1){
  153. cout << "MysterySortB is ";
  154. }
  155.  
  156. if(i==2){
  157. cout << "MysterySortC is ";
  158. }
  159.  
  160. if(i==3){
  161. cout << "MysterySortD is ";
  162. }
  163.  
  164. if(i==4){
  165. cout << "MysterySortE is ";
  166. }
  167.  
  168. for(int j = 0; j < 5; j++)
  169. {
  170. if(match[j].second == i)
  171. {
  172. if(j == 0){
  173. sort1 = "QuickSort";
  174. cout << sort1 << endl;
  175. }
  176.  
  177. if(j == 1){
  178. sort2 = "MergeSort";
  179. cout << sort2 << endl;;
  180. }
  181.  
  182. if(j == 2){
  183. sort3 = "InsertSort";
  184. cout << sort3 << endl;
  185. }
  186.  
  187. if(j == 3){
  188. sort4 = "SelectionSort";
  189. cout << sort4 << endl;
  190. }
  191.  
  192. if(j == 4){
  193. sort5 = "BubbleSort";
  194. cout << sort5 << endl;
  195. }
  196. }
  197. }
  198. }
  199.  
  200. cout << endl;
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement