Write a function reverseQueue, which takes a queue object as input parameter and uses a stack object to reverse the elements of the queue.

 Write a function reverseQueue, which takes a queue object as input parameter and uses a stack object to reverse the elements of the queue.


#include <bits/stdc++.h>

#include<iostream>

using namespace std;

//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();

}

}

int main()

{

queue<int> Queue;

Queue.push(10);

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);

cout<<"\t\t\t\tShow Reverse Queue  "<<endl;

cout<<endl;

reverseQueue(Queue);

Print(Queue);

}




Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.