Try maintaining at every node in the queue the minimum till that node
in addition to the value.
min() will return the min val stored at the top.

On Thu, Oct 8, 2009 at 9:22 AM, Manisha <pgo...@gmail.com> wrote:
>
>
>
> @harit
>
> Maintaining only one data member, minimum will not suffice. As we may
> call min() any number of time and every time it should return the
> minimum of all data members.
>
> @sharad
> Thanks for direction.
> In your implementation, stack.top() and stack.pop() are going to
> return same value.
> So min() and pop() will return the same value that is not correct.
> Lets say we have to push 2 items in stack , 2 & 5 respectively.
> It will be maintained as,
> 2
> 2
> 5
> 5
> Now min() will return 2 but pop() will also return 2. While pop() must
> return 5.
> I guess, little variation of your code will work fine. I will work it
> out.
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to