@Kirubakaran : still space complexity is O(n) due to stack.Can it be solved in space complexity O(1).
On Wed, Jun 20, 2012 at 8:00 PM, Kirubakaran D <kirubakara...@gmail.com>wrote: > You could use recursion. > > def reverse_Q q > if !q.isEmpty? > el = q.dequeue > nQ = reverse_Q(q) > nQ.enqueue el > return nQ > end > return q > end > > > > On Wednesday, June 20, 2012 6:57:23 PM UTC+5:30, Navin Kumar wrote: >> >> Use only standard operation of Queue like: EnQueue, DeQueue, IsEmptyQueue >> etc >> >> On Wed, Jun 20, 2012 at 6:50 PM, amrit harry <dabbcomput...@gmail.com>wrote: >> >>> can we create other methods or we have to use only enqueue and >>> dequeue...? if yes then simply >>> for(i=0;i<=n/2;i++) >>> swap(i,n-i); >>> >>> >>> >>> On Wed, Jun 20, 2012 at 6:46 PM, Navin Kumar >>> <algorithm.i...@gmail.com>wrote: >>> >>>> @Saurabh: queue will be remain unchanged according to your algorithm. >>>> Because if you will delete an element from front and add at rear no change >>>> will be there. After n iteration front will be pointing to same element and >>>> rear will also point to same element. >>>> >>>> Correct me if i am wrong. :) >>>> >>>> >>>> On Wed, Jun 20, 2012 at 6:39 PM, saurabh singh >>>> <saurabh.n...@gmail.com>wrote: >>>> >>>>> count the size of queue : O(n) >>>>> loop for n and do remove and add in queue : O(n) >>>>> >>>>> Total : O(n) >>>>> >>>>> >>>>> On Wed, Jun 20, 2012 at 6:34 PM, Navin Kumar <algorithm.i...@gmail.com >>>>> > 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/-/kepls-8qRwgJ<https://groups.google.com/d/msg/algogeeks/-/kepls-8qRwgJ> >>>>>> . >>>>>> To post to this group, send email to algogeeks@googlegroups.com. >>>>>> To unsubscribe from this group, send email to algogeeks+unsubscribe@* >>>>>> *googlegroups.com <algogeeks%2bunsubscr...@googlegroups.com>. >>>>>> For more options, visit this group at http://groups.google.com/** >>>>>> group/algogeeks?hl=en<http://groups.google.com/group/algogeeks?hl=en> >>>>>> . >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Thanks & Regards, >>>>> Saurabh >>>>> >>>>> -- >>>>> 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+unsubscribe@** >>>>> googlegroups.com <algogeeks%2bunsubscr...@googlegroups.com>. >>>>> For more options, visit this group at http://groups.google.com/** >>>>> group/algogeeks?hl=en <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+unsubscribe@** >>>> googlegroups.com <algogeeks%2bunsubscr...@googlegroups.com>. >>>> For more options, visit this group at http://groups.google.com/** >>>> group/algogeeks?hl=en <http://groups.google.com/group/algogeeks?hl=en>. >>>> >>> >>> >>> >>> -- >>> Thanks & Regards >>> Amritpal singh >>> >>> -- >>> 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+unsubscribe@** >>> googlegroups.com <algogeeks%2bunsubscr...@googlegroups.com>. >>> For more options, visit this group at http://groups.google.com/** >>> group/algogeeks?hl=en <http://groups.google.com/group/algogeeks?hl=en>. >>> >> >> -- > 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/-/qmLUaTNJns8J. > > 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.