|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectstructure.AbstractStructure<ELTTYPE>
structure.AbstractLinear<ELTTYPE>
structure.AbstractStack<ELTTYPE>
structure.StackList<ELTTYPE>
public class StackList<ELTTYPE>
An implementation of a stack, based on lists. The head of the stack is stored at the head of the list, allowing the stack to grow and shrink in constant time. This stack implementation is ideal for applications that require a dynamically resizable stack that expands in constant time.
Example usage:
To reverse a string, we would use the following:
public static void main(String[] arguments)
{
if(arguments.length > 0){
StackList reverseStack = new StackList();
String s = arguments[0];
for(int i=0; i < s.length(); i++){
reverseStack.push(new Character(s.charAt(i)));
}
while(!reverseStack.empty()){
System.out.print(reverseStack.AbstractStack.pop());
}
System.out.println();
}
}
Stack,
StackVector,
StackArray,
AbstractStack| Constructor Summary | |
|---|---|
StackList()
Construct an empty stack. |
|
| Method Summary | |
|---|---|
void |
add(ELTTYPE value)
Add a value to the top of the stack. |
void |
clear()
Remove all elements from the stack. |
boolean |
empty()
Determine if the stack is empty. |
ELTTYPE |
get()
Get a reference to the top value in the stack. |
java.util.Iterator<ELTTYPE> |
iterator()
Returns an iterator for traversing the structure. |
ELTTYPE |
remove()
Remove a value from the top of the stack. |
int |
size()
Determine the number of elements in the stack. |
java.lang.String |
toString()
Construct a string representation of the stack. |
| Methods inherited from class structure.AbstractStack |
|---|
getFirst, peek, pop, push |
| Methods inherited from class structure.AbstractLinear |
|---|
remove |
| Methods inherited from class structure.AbstractStructure |
|---|
contains, elements, hashCode, isEmpty, values |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface structure.Stack |
|---|
getFirst, peek, pop, push |
| Methods inherited from interface structure.Structure |
|---|
contains, elements, isEmpty, remove, values |
| Constructor Detail |
|---|
public StackList()
| Method Detail |
|---|
public void clear()
clear in interface Structure<ELTTYPE>public boolean empty()
empty in interface Linear<ELTTYPE>empty in interface Stack<ELTTYPE>empty in class AbstractLinear<ELTTYPE>AbstractStructure.isEmpty()public java.util.Iterator<ELTTYPE> iterator()
Structure
iterator in interface java.lang.Iterable<ELTTYPE>iterator in interface Structure<ELTTYPE>AbstractIterator,
Iterator,
Enumeration,
Structure.elements()public ELTTYPE get()
get in interface Linear<ELTTYPE>get in interface Stack<ELTTYPE>public void add(ELTTYPE value)
add in interface Linear<ELTTYPE>add in interface Stack<ELTTYPE>add in interface Structure<ELTTYPE>item - The value to be added.AbstractStack.push(ELTTYPE)public ELTTYPE remove()
remove in interface Linear<ELTTYPE>remove in interface Stack<ELTTYPE>AbstractStack.pop()public int size()
size in interface Linear<ELTTYPE>size in interface Stack<ELTTYPE>size in interface Structure<ELTTYPE>public java.lang.String toString()
toString in class java.lang.Object
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||