| 51 | |
| 52 | |
| 53 | void SortStack :: sort() |
| 54 | { |
| 55 | priority_queue<int,vector<int>,greater<int>>pq; // declaring min heap |
| 56 | |
| 57 | while(!st.empty()) // run the loop till the stack is not empty |
| 58 | { |
| 59 | pq.push(st.top()); |
| 60 | st.pop(); |
| 61 | } |
| 62 | |
| 63 | while(!pq.empty()) // run the loop till the min heap is not empty |
| 64 | { |
| 65 | st.push(pq.top()); |
| 66 | pq.pop(); |
| 67 | } |
| 68 | } |