Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "lab.h"
- using namespace std;
- void countingSort(lab::Queue<int>& q){
- int mx = INT_MIN;
- int size = q.size();
- for(int i = 0; i < q.size(); ++i){
- int front = q.front();
- mx = max(mx, front);
- q.pop();
- q.push(front);
- }
- auto count = vector<int>(mx + 1, 0);
- for(int i = 0; i < size; ++i){
- int front = q.front();
- count[front]++;
- q.pop();
- }
- for(int i = 0; i < count.size(); ++i){
- for(int j = 0; j < count[i]; ++j){
- q.push(i);
- }
- }
- }
- int main() {
- srand(time(nullptr));
- lab::Queue<int> queue(7);
- for(int i = 0; i < queue.size(); ++i)
- queue.push(rand() % 10);
- queue.print();
- cout << endl;
- countingSort(queue);
- queue.print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement