forked from mr-professor4569/Data_Structures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverse Queue.cpp
More file actions
44 lines (40 loc) · 847 Bytes
/
Reverse Queue.cpp
File metadata and controls
44 lines (40 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <bits/stdc++.h>
using namespace std;
// Utility function to print the queue
void Print(queue<int>& Queue)
{
while (!Queue.empty()) {
cout << Queue.front() << " ";
Queue.pop();
}
}
// Function to reverse the queue
void reverseQueue(queue<int>& Queue)
{
stack<int> Stack;
while (!Queue.empty()) {
Stack.push(Queue.front());
Queue.pop();
}
while (!Stack.empty()) {
Queue.push(Stack.top());
Stack.pop();
}
}
// Driver code
int main()
{
queue<int> Queue;
Queue.push(10); // push elements of your choice , this is just an example
Queue.push(20);
Queue.push(30);
Queue.push(40);
Queue.push(50);
Queue.push(60);
Queue.push(70);
Queue.push(80);
Queue.push(90);
Queue.push(100);
reverseQueue(Queue);
Print(Queue);
}