Re: [algogeeks] Implement a Queue using a stack

2010-02-08 Thread chandra sekhar varma
As we have the standard implementation for the Queue using two stacks, i think we can use that logic here. by using the Operating system stack as the second stack, i mean to say using recursion we can achieve it. Suppose we call the stack as S1 and it has two functions namely push and pop, The imp

[algogeeks] Re: Design a stack to perform push(), pop() and retrieve minimum in constant time.

2009-10-16 Thread chandra sekhar varma
Hi Guys A more space efficient solution is here push(x) { if stack.empty() { stack.push(x); stack.push(x); } else { if x > stack.top() { min = stack.pop() stack.push(x) stack.push(min) } else