|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcodesimian.StackNeverEmpty<K>
public class StackNeverEmpty<K>
A stack that holds its first object constant so it can never become empty.
You can change the bottom object, but only with
Can use the new "generics" syntax for types. Example:
StackNeverEmpty
String s = stringStack.pop(); //no cast
//pop returns the bottom String but does not remove it
Implemented as a singly-linked list.
This should become a subclass of CS.
If you want a stack of Number's or CS's, use a NumberStack.NeverEmpty instead.
NumberStack
Constructor Summary | |
---|---|
StackNeverEmpty(K pushMe)
pushMe permanently becomes the lowest object in this stack |
Method Summary | |
---|---|
K |
peek()
Returns the object on top of the stack |
K |
pop()
Returns the object at the top of the stack. |
void |
push(K addMe)
|
K |
replace(K replaceTopWithMe)
Replaces the top object with replaceTopWithMe and returns the removed object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public StackNeverEmpty(K pushMe)
Method Detail |
---|
public void push(K addMe)
public K pop()
public K peek()
public K replace(K replaceTopWithMe)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |