Author |
Topic: Queue using 1 stack (Read 2932 times) |
|
computer
Newbie
Posts: 5
|
|
Queue using 1 stack
« on: Feb 11th, 2009, 9:14pm » |
Quote Modify
|
Can a queue be implemented using a single stack ?
|
|
IP Logged |
|
|
|
johny_cage
Full Member
Gender:
Posts: 155
|
|
Re: Queue using 1 stack
« Reply #1 on: Feb 11th, 2009, 11:24pm » |
Quote Modify
|
if it can be made, then why there are two different entities No, it can not be done. You will require two stacks to implement a queue.
|
|
IP Logged |
|
|
|
nks
Junior Member
Gender:
Posts: 145
|
|
Re: Queue using 1 stack
« Reply #2 on: Feb 12th, 2009, 12:31am » |
Quote Modify
|
Quote:No, it can not be done. You will require two stacks to implement a queue. |
| You can even simulate a queue using only one stack. The second (temporary) stack can be simulated by the call stack of recursive calls to the insert method.
|
|
IP Logged |
|
|
|
towr
wu::riddles Moderator Uberpuzzler
Some people are average, some are just mean.
Gender:
Posts: 13730
|
|
Re: Queue using 1 stack
« Reply #3 on: Feb 12th, 2009, 1:02am » |
Quote Modify
|
on Feb 12th, 2009, 12:31am, nks wrote:You can even simulate a queue using only one stack. The second (temporary) stack can be simulated by the call stack of recursive calls to the insert method. |
| Making recursive calls requires a second stack -- the function stack.
|
|
IP Logged |
Wikipedia, Google, Mathworld, Integer sequence DB
|
|
|
|