This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes how to programe a stack process for first in and last out! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to programe a stack process for first in and last out!" Watch "how to programe a stack process for first in and last out!" New topic
Author

how to programe a stack process for first in and last out!

sue song
Greenhorn

Joined: Sep 25, 2003
Posts: 1
Hello, I am a beginner, and now there is one question which I cannot get any clue of it. Could any one have some hint of it? Thanks very much in advance!
An integer stack can be thought of as an array of integers which behaves according to First in last out principle; the first integer put to the stack will be the last one which gets out of the stack. Write an object oriented program which simulates the way numbers are put to a stack and the way they are retrieved out of the stack of 10 numbers.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi Sue,
Welcome to JavaRanch!
Here's a basic outline of what you need to do:
1) Define a class IntegerStack .
2) Give IntegerStack a member variable that is an int array.
3) Give IntegerStack a member variable used as an index to "point" to the top of the stack.
4) define a method push(int) which adds an integer to the stack.
5) define a method pop() which removes the integer on the top of the stack and returns it.
Why not see how far you can get with this, then come back to this thread and ask more specific questions if you get stuck.


[Jess in Action][AskingGoodQuestions]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I had to read your topic line about 10 times ... I've usually heard FIFO First In First Out and LIFO Last In First Out. I have seen FILO First In Last Out but long ago and not very often. It should be same as LIFO, yes? Puts me in mind of those parking lots in New York City where you see your car way back in the corner with dozens of others in the way. First In, Last Out!
Ernest's API suggestions are perfect. And here's a good exercise in "information hiding". Do you want to use his "array" suggestion for storing the data? Or do you have another idea? The API doesn't change so your decision is nicely hidden.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to programe a stack process for first in and last out!