Advertisement
Guest User

Untitled

a guest
Feb 27th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <random>
  5. #include <ctime>
  6. #include <fstream>
  7.  
  8. #include "les1.h"
  9.  
  10.  
  11.  
  12. vector<elem> rand_arr(int n) {
  13. vector<elem> v(n);
  14. srand(time(NULL));
  15. for (int i = 0; i < n; ++i)
  16. v[i] = rand() % 10000;
  17.  
  18. return v;
  19. }
  20.  
  21.  
  22. template<typename It>
  23. void choice_sort(It begin, It end) {
  24. for (auto it = begin; it != end; ++it) {
  25.  
  26. It min = it;
  27.  
  28. for (auto it2 = it + 1; it2 != end; ++it2)
  29. if (*it2 < *min)
  30. min = it2;
  31.  
  32. if (min != it)
  33. swap(*it, *min);
  34. }
  35. }
  36.  
  37. int main() {
  38. vector<elem> w{ 1, 3, 5, 7, 8, 23 };
  39. ofstream ofs("task1.csv");
  40. ofs << "name;elements;time(sec);equalents;copys" << endl;
  41. for (int i = 2000; i <= 8000; i += 2000) {
  42. auto r = rand_arr(i);
  43. vector<elem> v = r;
  44. vector<elem> v2 = r;
  45. elem::ccop = 0;
  46. time_t start1 = clock();
  47. sort(v.begin(), v.end());
  48. ofs << "sort;" << i << ';' << double(clock() - start1) / CLOCKS_PER_SEC << ';'<< elem::ccop << ';' << elem::ceqv << ';' << endl;
  49.  
  50. elem::ceqv = 0;
  51. elem::ccop = 0;
  52. time_t start2 = clock();
  53. choice_sort(v2.begin(), v2.end());
  54. ofs << "ch_sort;"<<i << ';'<< double(clock() - start2) / CLOCKS_PER_SEC << ';' << elem::ccop << ';' << elem::ceqv << ';' << endl;
  55.  
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement