wu :: forums
« wu :: forums - Implementing stack »

Welcome, Guest. Please Login or Register.
Nov 28th, 2024, 11:57am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: Grimbal, ThudnBlunder, Eigenray, Icarus, towr, SMQ, william wu)
   Implementing stack
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Implementing stack  (Read 562 times)
tuxilogy
Newbie
*





   


Posts: 45
Implementing stack  
« on: May 6th, 2006, 11:58pm »
Quote Quote Modify Modify

How to implement a Stack by using two queues
IP Logged
SMQ
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 2084
Re: Implementing stack  
« Reply #1 on: May 7th, 2006, 6:38am »
Quote Quote Modify Modify

Why am I starting to get the feeling we're doing your 2nd-year CS homework for you... Wink
 
Here's a hint: there are two simple implementations; depending on which one you choose, either push or pop (of the implemented stack) is going to be inefficient.
 
--SMQ
IP Logged

--SMQ

gaps
Newbie
*





   


Gender: male
Posts: 1
Re: Implementing stack  
« Reply #2 on: May 9th, 2006, 3:25am »
Quote Quote Modify Modify

Take the first queue , enqueue the element when the operation is Push.
When the operation is pop, dequeue the first queue and  enqueue all the elements in the second queue except for the last element in the first queue. Return this element as popped element. Swap the references of the 2 queues.
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board