R
ravi
Can any body tell me
How to implement a stack using two queues
Thax in advance
How to implement a stack using two queues
Thax in advance
Can any body tell me
How to implement a stack using two queues
Thax in advance
Don't you mean implement a queue using 2 stacks, which is a standard
homework problem?
Which is almost certainly also a homework question...ravi said:No
It is How to implement a stack using two queues
Can any body tell me
How to implement a stack using two queues
Thax in advance
ravi said:How to implement a stack using two queues?
You need to define 'stack' and 'queue'.
Sam said:I think the idea is to simulate LIFO by having data structures that
works in FIFO order.
Lets assume there are 2 queues Q1,Q2
the most simple way that I think, would be
pop -
Delete item from front of Q1 and return.
push -
1. if Q1 is not empty, delete all item one by one from Q1 and insert
in Q2.
2. insert item in Q1.
3. delete all item one by one from Q2 and insert in Q1.
the Step2 ensures that the item is most recently added item would be
at first in Q1's front ...that means ..the most recent item will be
deleted when requested.
that's what the LIFO is.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.