By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,166 Members | 1,130 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,166 IT Pros & Developers. It's quick & easy.

implement a stack using two queues

P: n/a
Can any body tell me

How to implement a stack using two queues

Thax in advance

Aug 1 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Jul 31, 10:22 pm, ravi <dceravigu...@gmail.comwrote:
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?

Aug 1 '07 #2

P: n/a
On Aug 1, 7:31 am, Gene <gene.ress...@gmail.comwrote:
On Jul 31, 10:22 pm, ravi <dceravigu...@gmail.comwrote:
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?
No
It is How to implement a stack using two queues

Aug 1 '07 #3

P: n/a
ravi wrote:
On Aug 1, 7:31 am, Gene <gene.ress...@gmail.comwrote:
>>On Jul 31, 10:22 pm, ravi <dceravigu...@gmail.comwrote:

>>>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?


No
It is How to implement a stack using two queues
Which is almost certainly also a homework question...
Aug 1 '07 #4

P: n/a
CoL
On Aug 1, 7:22 am, ravi <dceravigu...@gmail.comwrote:
Can any body tell me

How to implement a stack using two queues

Thax in advance
Hi ,
I am just giving you hint for its possible algo.

1. Use one queue to push data into...say Q-a.Make a common push() and
pop() common function passing front and rear initially NULL.

2. For pop operation,
if (Q-a.front!=Q-a.rear)
{
pop and add to Q-b;
}
else
{
pop(); //this is our output
Q-a.front=Q-b.front
Q-a.rear=Q-b.rear;
Q-b.front=Q-b.rear=NULL
}

Hope this helps.

~Col

Aug 1 '07 #5

P: n/a
ravi wrote:
How to implement a stack using two queues?
You need to define 'stack' and 'queue'.
Aug 1 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.