Advertisement
lukusm

main.cpp

Dec 2nd, 2014
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. #include "headers.h"
  2. #include "functions.h"
  3. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  4. using namespace std;
  5.  
  6. vector<double> toSort1;
  7. vector<double> toSort2;
  8. vector<double> toSort3;
  9.  
  10. vector<double> genTimes1;
  11. vector<double> genTimes2;
  12. vector<double> genTimes3;
  13.  
  14. vector<double> sortTimes1;
  15. vector<double> sortTimes2;
  16. vector<double> sortTimes3;
  17.  
  18. string fName = "sort_times.txt";
  19. //string fileNames[3] = "BubbleSortResults.txt","SelectionSortResults.txt","InsertionSortResults.txt"
  20. const int range = 1000;
  21.  
  22. int main(int argc, char** argv) {
  23.  
  24. srand(time(NULL));
  25. for (int howMany = 100; howMany<=1000000; howMany*=10) {
  26.     // I sortowanie - bubble
  27.     clock_t start=clock();
  28.     randomNumGen(howMany, range, toSort1);
  29.     clock_t finish=clock();
  30.     double gTime = timesDiff(start,finish);
  31.     genTimes1.push_back(gTime);
  32.     clock_t start2 = clock();
  33.     BubbleSort(toSort1);
  34.     clock_t finish2=clock();
  35.     double sTime = timesDiff(start2,finish2);
  36.     sortTimes1.push_back(sTime);
  37.    
  38.     // II sortowanie - selection
  39.     start=clock();
  40.     randomNumGen(howMany, range, toSort2);
  41.     finish=clock();
  42.     gTime = timesDiff(start,finish);
  43.     genTimes2.push_back(gTime);
  44.     start2 = clock();
  45.     SelectionSort(toSort2);
  46.     finish2=clock();
  47.     sTime = timesDiff(start2,finish2);
  48.     sortTimes2.push_back(sTime);
  49.    
  50.     // III sortowanie - insertion
  51.     start=clock();
  52.     randomNumGen(howMany, range, toSort3);
  53.     finish=clock();
  54.     gTime = timesDiff(start,finish);
  55.     genTimes3.push_back(gTime);
  56.     start2 = clock();
  57.     InsertionSort(toSort3);
  58.     finish2=clock();
  59.     sTime = timesDiff(start2,finish2);
  60.     sortTimes3.push_back(sTime);
  61.    
  62.     toSort1.clear();
  63.     toSort2.clear();
  64.     toSort3.clear();
  65. }
  66.  
  67. writeResults(fName,sortTimes1, sortTimes2, sortTimes3);
  68.  
  69. system("pause");
  70. /*sort.push_back(1.06);
  71. sort.push_back(5.06);
  72. sort.push_back(3.06);
  73. sort.push_back(2.06);
  74. sort.push_back(1.06);
  75. sort.push_back(7.06);
  76. sort.push_back(9.06);*/
  77.  
  78. //for (int i=0;i<sort.size();i++)
  79. //cout<< sort[i]<<" ";
  80. //cout<<endl;
  81. //BubbleSort(sort);
  82. //SelectionSort(sort);
  83. //InsertionSort(sort);
  84. //for (int i=0;i<sort.size();i++)
  85. //cout<< sort[i]<<" ";
  86.     return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement