Abhishek Sharma : swap is not allowed because you can push at only one side of queue. it's not dequeue.
On Wed, Jun 20, 2012 at 11:21 PM, Abhishek Sharma <abhi120...@gmail.com>wrote: > using recursion, > > reverse(queue,front,rear) { > if( front < rear ) { > swap( queue[front], queue[rear] ); > reverse( queue, front+1, rear-1); > } > } > > On Wed, Jun 20, 2012 at 11:53 PM, Sreeprasad Govindankutty < > sreeprasad...@gmail.com> wrote: > >> Just a query : >> >> If the queue is implemented as an array, then is it not possible to swap >> the elements from the last and first position onwards until you reach >> middle point. Wont this use O(1) space and O(n/2) time. >> >> >> >> On Wed, Jun 20, 2012 at 1:56 PM, Hassan Monfared <hmonfa...@gmail.com>wrote: >> >>> void Reverse(std::queue<int> &pQ) >>> { >>> if(pQ.empty()) >>> return; >>> int item=pQ.front(); >>> pQ.pop(); >>> Reverse(pQ); >>> pQ.push(item); >>> } >>> Regards >>> >>> On Wed, Jun 20, 2012 at 9:41 PM, enchantress <elaenjoy...@gmail.com>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 algogeeks@googlegroups.com. >>>> To unsubscribe from this group, send email to >>>> algogeeks+unsubscr...@googlegroups.com. >>>> 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 algogeeks@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com. >>> 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 algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > Abhishek Sharma > Under-Graduate Student, > PEC University of Technology > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.