|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectgeneseo.cs.sc.List
geneseo.cs.sc.Stack
Represents stacks of arbitrary objects. This class reflects a view of a stack as a kind of list, albeit one with some unique operations (push, pop, etc.), and in which some of the traditional list operations (find, delete, etc.) do nothing. The overall result is a class whose instances behave like standard stacks.
This class was created to support the text Algorithms & Data Structures: The Science of Computing by Doug Baldwin and Greg Scragg. All references herein to "the text" refer to that book. This stack class is the one described in Chapter 12, including full implementations of some methods that were "left to an exercise" in the text.
| Constructor Summary | |
Stack()
Initialize an empty stack. |
|
| Method Summary | |
void |
concat(List extraList)
Warns the user that concatenation is not a standard stack operation. |
void |
delete(java.lang.Object value)
Warns the user that general deletion is not a standard stack operation. |
boolean |
find(java.lang.Object target)
Warns the user that searching is not a standard stack operation. |
List |
makeNewList()
Create a new list that is an instance of Stack,
as required of any subclass of List. |
java.lang.Object |
pop()
Retrieve and remove the top object from a stack. |
void |
printStack()
Print a stack. |
void |
push(java.lang.Object newItem)
Adds an object to a stack. |
| Methods inherited from class geneseo.cs.sc.List |
addItem, copy, getAndRemove, getFirst, getRest, isEmpty, printList, printListForward, removeItem, restore, save, setFirstItem, setRest, toString |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public Stack()
Stack s = new Stack();
| Method Detail |
public List makeNewList()
Stack,
as required of any subclass of List. Clients of
Stack generally do not send this message themselves,
but code inside inherited methods relies on it.
makeNewList in class ListStack objectpublic void push(java.lang.Object newItem)
s.push( "hello" );
newItem - The object to add to the stack.public java.lang.Object pop()
Object top = s.pop();
This message has a precondition that the stack is not empty.
public void printStack()
s.printStack();
public void concat(List extraList)
concat in class ListextraList - The list to be added to the end of the current list.public boolean find(java.lang.Object target)
find in class Listtarget - The object to look for in the list.
false, indicating that all attempts to search stacks fail.public void delete(java.lang.Object value)
delete in class Listvalue - The object to remove from the list.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||