16. Queue Reversal
My Approach
Aproach-1 (Using rescusive stack)
Time and Auxiliary Space Complexity
Code (C++)
class Solution
{
public:
void reverse(queue<int>& q)
{
if (!q.empty())
{
int temp = q.front();
q.pop();
reverse(q);
q.push(temp);
}
}
queue<int> rev(queue<int> q)
{
reverse(q);
return q;
}
};Approach-2 (Using STL stack)
Time and Auxiliary Space Complexity
Code (C++)
Contribution and Support
Last updated