void Reverse(std::queue<int> &pQ)
{
if(pQ.empty())
return;
int item=pQ.front();
pQ.pop();
Reverse(pQ);
pQ.push(item);
}
RegardsOn Wed, Jun 20, 2012 at 9:41 PM, enchantress <[email protected]> wrote: > Queues are basically linked lists with head and tail pointers. It is > possible to reverse the list by change of pointers in O(n) time n O(1) > space. > PS: Not considering queue ADT with enqueue dequeue operations. > > > On Wednesday, 20 June 2012 18:34:46 UTC+5:30, Navin Kumar wrote: >> >> How to reverse a Queue . >> >> Constraints: Time complexity O(n). space complexity: O(1) >> >> -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/algogeeks/-/syRXPuMjBpkJ. > > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
