Using two queues make a stack

Using two queues make a stack

Page 1 of 1

4 Replies - 10673 Views - Last Post: 14 February 2010 - 02:54 PM Rate Topic: -----

#1 skkskiran  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-May 08

Using two queues make a stack

Post icon  Posted 14 May 2008 - 02:28 AM

Hi Friends
I am confused with one question..?

Q : Using two queues make a stack..? how to do it ..? plz any logic u have plz provide me.


Thanking you
yours faitfully
kirankumar.s
Is This A Good Question/Topic? 0
  • +

Replies To: Using two queues make a stack

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3116
  • View blog
  • Posts: 19,153
  • Joined: 14-September 07

Re: Using two queues make a stack

Posted 14 May 2008 - 04:05 AM

I wonder why?

There are LIFO and FIFO structures created differently for a reason.
Was This Post Helpful? 0
  • +
  • -

#3 ajaymatrix  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 1
  • View blog
  • Posts: 410
  • Joined: 15-May 07

Re: Using two queues make a stack

Posted 14 May 2008 - 05:00 AM

same question KYA asked: Why?
Was This Post Helpful? 0
  • +
  • -

#4 e-switcher  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-October 09

Re: Using two queues make a stack

Posted 10 November 2009 - 04:36 PM

i have this as assignement for my university too ! :D
Was This Post Helpful? 0
  • +
  • -

#5 Guest_Ronny*


Reputation:

Re: Using two queues make a stack

Posted 14 February 2010 - 02:54 PM

make 2 queues.
Push() has the same implementation as Queue().
Pop() would be:
- keep dequeuing the elements on the used queue until only one element is left. When we dequeue each element, immediately queue it into the other one.
- Remove and return the last one element left.

So, we always use one queue except for Pop() method.
Was This Post Helpful? 0

Page 1 of 1