• Post Reply Bookmark Topic Watch Topic
  • New Topic

howto build a queue from 2 stacks  RSS feed

 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the general idea of the solution

what is the trick??

can you tell me in general how to build it??
 
Joe Ess
Bartender
Posts: 9439
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a problem with the advice given the last time you asked this same question?
There's only one way to learn how to code, and that's to write code. Give it a try. If you still have problems, post your code and we can give you a hand.
 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what should i do in the case of
for example:
if each stack has 5 cells
and i pushed only 3 in the 1st one
and i want to make the dequeue opearation

you said that that we pop from the second one
but it still empty

i only push objects into the second one if the first one
is full

??
 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i thought of a method to build it

we push all of the members into stack one
and if we want to make a deqeue operation we pop all of our members
from the first stack and push them into the second one
and then we pop our desired member
and then we pop from the second stack and push into the first one

my only problem remains what should i do in case if the
1st stack gets full and we still want to push

but i geard that the stacks in java are infinite
is it true??
 
Joe Ess
Bartender
Posts: 9439
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no preset limit to the size of a stack. There will be a physical limit that depends on available memory space, size of the virtual machine and so on.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!