Advertisement
dimon-torchila

Untitled

Jan 5th, 2023
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. #include "lab1.h"
  2. #include "lab2.h"
  3. #include "lab3.h"
  4.  
  5. using namespace std;
  6.  
  7.  
  8.  
  9. void sort(lab1::Queue<int>& q){
  10. q.N_op+=3;
  11. for(int i = 0; i < q.size(); ++i){
  12. q.N_op+= 12;
  13. int mn = INT_MAX;
  14. int first = 0, temp = 0;
  15. bool swap = true;
  16. for(int j = 0; j < i; ++j){
  17. q.N_op++;
  18. temp = q.front();
  19. q.pop();
  20. q.push(temp);
  21. }
  22. first = q.front();
  23. for(int j = i; j < q.size(); ++j){
  24. temp = q.front();
  25. mn = min(q.front(), mn);
  26. q.pop();
  27. q.push(temp);
  28. q.N_op+=3;
  29. }
  30. for(int j = 0; j < i; ++j){
  31. q.N_op++;
  32. temp = q.front();
  33. q.pop();
  34. q.push(temp);
  35. }
  36. for(int j = i; j < q.size(); ++j){
  37. q.N_op+=5;
  38. temp = q.front();
  39. q.pop();
  40. if(temp == mn && swap) {
  41. q.push(first);
  42. swap = false;
  43. }
  44. else if(i == j) {
  45. q.push(mn);
  46. }
  47. else
  48. q.push(temp);
  49. }
  50. }
  51. }
  52.  
  53. int main(){
  54. for (int a = 5000; a <= 10000; a += 500) {
  55. size_t n = 0;
  56. lab1::Queue<int> queue(a);
  57. srand(time(NULL));
  58. ::clock_t start = ::clock();
  59. for(int i = 0; i < a; ++i)
  60. queue.push(::rand() % (5 * a));
  61. cout << "init of " << a << " elements takes " <<
  62. (::clock() - start) * 1000 /CLOCKS_PER_SEC << " millisec\n";
  63. start = ::clock();
  64. sort(queue);
  65. cout << "sort of " << a << " elements takes " <<
  66. (::clock() - start) * 1000 /CLOCKS_PER_SEC << " millisec\n";
  67. cout << "takes " << queue.N_op << " N_op\n\n";
  68. }
  69.  
  70. }
  71. /*int main(){
  72. lab2::Graph G(4);
  73. set<int> visited;
  74. int cCount;
  75. cin >> cCount;
  76. for(int i = 0; i < cCount; ++i){
  77. string first_v, second_v;
  78. int weight;
  79. cin >> first_v >> second_v >> weight;
  80. G.Add_E(first_v, second_v, weight);
  81. }
  82. G.print();
  83.  
  84.  
  85. return 0;
  86. }*/
  87. /*
  88. 4
  89. a c 5
  90. b c 1
  91. c b 3
  92. d a 7
  93. */
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement