Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <thread>
  3. #include <mutex>
  4. #include <string.h>
  5. #include <ctime>
  6. #include "sort.cc"
  7.  
  8. using namespace std;
  9.  
  10. void new_array(int *&mas, int &length, const int el)
  11. {
  12. int *newArray = new int[length + 1];
  13. for (int l = 0; l < length; l++)
  14. {
  15. newArray[l] = mas[l];
  16. }
  17. newArray[length] = el;
  18. mas = newArray;
  19. }
  20.  
  21. int main() {
  22. int* mas = new int[2];
  23. mas[0] = 9;
  24. mas[1] = 8;
  25. cout << "Work time posl" << " " << "Work time par" << " " << "Size" <<endl;
  26.  
  27. for (int i = 2; i < 100; i++)
  28. {
  29. std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
  30. merge_sort_par(mas, i);
  31. std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
  32. cout << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
  33. cout.width(23);
  34. std::chrono::steady_clock::time_point startp = std::chrono::steady_clock::now();
  35. merge_sort_pos(mas, i);
  36. std::chrono::steady_clock::time_point endp = std::chrono::steady_clock::now();
  37. cout << std::chrono::duration_cast<std::chrono::microseconds>(endp - startp).count();
  38. cout.width(23);
  39. cout << i << endl;
  40. new_array(mas,i,i);
  41. for (int iter = 0; iter < i - 1; iter++)
  42. {
  43. if (mas[iter] > mas[iter + 1])
  44. {
  45. cout << "The sort isn't correct" << endl;
  46. }
  47. }
  48. }
  49.  
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement