Advertisement
dimon-torchila

Untitled

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