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.
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.
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
subject: how to programe a stack process for first in and last out!