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
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
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
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
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
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
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
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
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
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
@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.
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
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
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)
{
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
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
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
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
18 matches
Mail list logo