[algogeeks] Implement a queue using a stack

2010-03-22 Thread Pushpesh Gupta
How is it possible to implement a queue using a stack only? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Implement a queue using a stack

2010-03-22 Thread Prakhar Jain
By a do u mean a single stack ? Otherwise if you use 2 its v simple Best, Prakhar Jain http://web.iiit.ac.in/~prakharjain/ On Mon, Mar 22, 2010 at 12:56 AM, Pushpesh Gupta pushpes...@gmail.comwrote: How is it possible to implement a queue using a stack only? -- You received this message

Re: [algogeeks] Implement a queue using a stack

2010-03-22 Thread vikrant singh
how? can u xplain? On Mon, Mar 22, 2010 at 5:25 PM, Prakhar Jain prakh...@gmail.com wrote: By a do u mean a single stack ? Otherwise if you use 2 its v simple Best, Prakhar Jain http://web.iiit.ac.in/~prakharjain/ On Mon, Mar 22, 2010 at 12:56 AM, Pushpesh Gupta

Re: [algogeeks] Implement a queue using a stack

2010-03-22 Thread Prakhar Jain
A better version exists where amortized order is (1) for both opreations Best, Prakhar Jain http://web.iiit.ac.in/~prakharjain/ On Mon, Mar 22, 2010 at 6:56 PM, Brian brianfo...@gmail.com wrote: How is it possible to implement a queue using a stack only? Interesting, but tricky... You

Re: [algogeeks] Implement a queue using a stack

2010-03-22 Thread vikrant singh
Can u xplain what amortized means? On Mon, Mar 22, 2010 at 7:32 PM, Prakhar Jain prakh...@gmail.com wrote: A better version exists where amortized order is (1) for both opreations Best, Prakhar Jain http://web.iiit.ac.in/~prakharjain/ On Mon, Mar 22, 2010 at 6:56 PM, Brian

Re: [algogeeks] Implement a queue using a stack

2010-03-22 Thread Prakhar Jain
on an avg... say if you insert 10 elemets n remove 10. you consume O(20) Best, Prakhar Jain http://web.iiit.ac.in/~prakharjain/ On Mon, Mar 22, 2010 at 7:39 PM, vikrant singh vikrantsing...@gmail.comwrote: Can u xplain what amortized means? On Mon, Mar 22, 2010 at 7:32 PM, Prakhar

Re: [algogeeks] Implement a queue using a stack

2010-03-22 Thread Sundeep Singh
Hey Brian, Better still, for inserting in queue, just keep pushing onto the stack A. You need stack B only for dequeuing: for dequeuing, push all items into stack B, pop as many as you want from stack B and then push back all remaining items in stack A. Regards, Sundeep. On Mon, Mar 22, 2010

Re: [algogeeks] Implement a Queue using a stack

2010-02-11 Thread harit agarwal
but logic remains the same here...instead of own stack.system stack is being usedso wat's d difference. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To

Re: [algogeeks] Implement a Queue using a stack

2010-02-08 Thread MOHIT ....
but question is how to implement using one stack not two S1 and S2 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Implement a Queue using a stack

2010-02-08 Thread atul verma
I dont think its possible to implement a queue using a single stack. Atul On Mon, Feb 8, 2010 at 7:48 AM, MOHIT mohit...@gmail.com wrote: but question is how to implement using one stack not two S1 and S2 -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Implement a Queue using a stack

2010-02-08 Thread MOHIT ....
@atul : what u think about this method suppose if we implemented in array 1. for insert push in stack 2.for pop use a variable nd reverse stack in array -pop element form stack -again reverse ; -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group.

Re: [algogeeks] Implement a Queue using a stack

2010-02-08 Thread Pravin sinha
I guess you can do it using recursion(if allowed). Insert is any way straight forward(just by pushing onto the stack) but for removal you can do something like. remove() { topVal = stack.pop(); if(stack.isEmpty()) { //this is the only element return topVal } // get the last element

Re: [algogeeks] Implement a Queue using a stack

2010-02-08 Thread MOHIT ....
On Mon, Feb 8, 2010 at 2:13 PM, MOHIT mohit...@gmail.com wrote: @atul : what u think about this method suppose if we implemented in array 1. for insert push in stack 2.for pop use a variable nd reverse stack in array -pop element form stack -again reverse ; -- You received this

Re: [algogeeks] Implement a Queue using a stack

2010-02-08 Thread CHERUVU JAANU REDDY
This is code for queue using single stack #includestdio.h #includestdlib.h #define MAX 30 int stack[MAX],top=-1; void push(int num) { top++; if(top==MAX-1) { printf(Queue overflow\n); exit(0); } stack[top]=num; } int pop() { if(top==-1) {

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

[algogeeks] Implement a Queue using a stack

2010-02-07 Thread naren
how to Implement a Queue using a stack if space complexity is there... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Implement a Queue using a stack

2010-02-07 Thread CHERUVU JAANU REDDY
1) Take two stacks S1 and S2 For insertion operation: 1) push into S1 and if S2 is empty push into S2 and S2 is not empty pop all elements and push new element into S2 then push poped all elements (S2 contains all elements of S1 in reverse order) For deletion: Delete from S2

Re: [algogeeks] Implement a Queue using a stack

2010-02-07 Thread MOHIT ....
suppose if we implemented in array 1. for insert push in stack 2.for pop use a variable nd reverse stack in array -pop element form stack -again reverse ; -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to