HELP! Stack newbie
i'm having a trouble here with Stack. please help me.
how do i find minimum value in a predefined stack with a Object findMin(Stack ori) method? where do i have to declare the stack? in the static main or outside? could you guys please include the coding for implementing this method?
i'm new to stack and a bit slow with this one. please help me out. asap.:frusty: Thanks !
It seems you are confusing two things here:
* How you would go about finding the minimum value in a stack? This problem does not involve writing any code, but you would describe the steps needed completely and precisely enough to allow you to write code from the description you give.
* What code would reflect the process you described in step 1. This problem involves meeting all the requirements you have been given in the problem (which I'm guessing is homework of some sort.)
To address the first question, have a look at the Queue methods and think. Perhaps you could experiment with a pile of pieces of paper to see how, in fact, you would locate the minimum. Don't forget the fact that Stack inherits behaviour from its parent classes - you might decide to search it as you would any other list.
Post what you've come up with if you get stuck. Also suppose the stack consisted of 666, 1 Jan 2012 and "foo", which would be the minimum? Does the stack have to have some other property before the task even makes sense?
Once you figured out what you are going to do, you can sensibley start writing code.