Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "lab1.h"
- #include "lab2.h"
- #include "lab3.h"
- using namespace std;
- void sort(lab1::Queue<int>& q){
- for(int i = 0; i < q.size(); ++i){
- int mn = INT_MAX;
- int first = 0, temp = 0;
- bool swap = true;
- for(int j = 0; j < i; ++j){
- temp = q.front();
- q.pop();
- q.push(temp);
- }
- first = q.front();
- for(int j = i; j < q.size(); ++j){
- temp = q.front();
- mn = min(q.front(), mn);
- q.pop();
- q.push(temp);
- }
- for(int j = 0; j < i; ++j){
- temp = q.front();
- q.pop();
- q.push(temp);
- }
- for(int j = i; j < q.size(); ++j){
- temp = q.front();
- q.pop();
- if(temp == mn && swap) {
- q.push(first);
- swap = false;
- }
- else if(i == j) {
- q.push(mn);
- }
- else
- q.push(temp);
- }
- }
- }
- int main(){
- srand(time(nullptr));
- lab1::Queue<int> queue(50000);
- for(int i = 0; i < queue.size(); ++i)
- queue.push(rand() % 100000);
- queue.print();
- ::clock_t time = ::clock();
- sort(queue);
- time = ::clock() - time;
- cout << endl;
- queue.print();
- cout << 1000* time / CLOCKS_PER_SEC;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement