Advertisement
dimon-torchila

Untitled

Jan 3rd, 2023
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include "lab1.h"
  2. #include "lab2.h"
  3. #include "lab3.h"
  4.  
  5. using namespace std;
  6.  
  7.  
  8. void sort(lab1::Queue<int>& q){
  9.     for(int i = 0; i < q.size(); ++i){
  10.         int mn = INT_MAX;
  11.         int first = 0, temp = 0;
  12.         bool swap = true;
  13.         for(int j = 0; j < i; ++j){
  14.             temp = q.front();
  15.             q.pop();
  16.             q.push(temp);
  17.         }
  18.         first = q.front();
  19.         for(int j = i; j < q.size(); ++j){
  20.             temp = q.front();
  21.             mn = min(q.front(), mn);
  22.             q.pop();
  23.             q.push(temp);
  24.         }
  25.         for(int j = 0; j < i; ++j){
  26.             temp = q.front();
  27.             q.pop();
  28.             q.push(temp);
  29.         }
  30.         for(int j = i; j < q.size(); ++j){
  31.             temp = q.front();
  32.             q.pop();
  33.             if(temp == mn && swap) {
  34.                 q.push(first);
  35.                 swap = false;
  36.             }
  37.             else if(i == j) {
  38.                 q.push(mn);
  39.             }
  40.             else
  41.                 q.push(temp);
  42.         }
  43.     }
  44. }
  45.  
  46.  
  47. int main(){
  48.     srand(time(nullptr));
  49.     lab1::Queue<int> queue(50000);
  50.     for(int i = 0; i < queue.size(); ++i)
  51.         queue.push(rand() % 100000);
  52.     queue.print();
  53.     ::clock_t time = ::clock();
  54.     sort(queue);
  55.     time = ::clock() - time;
  56.     cout << endl;
  57.     queue.print();
  58.  
  59.     cout << 1000* time / CLOCKS_PER_SEC;
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement