|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object structure5.AbstractStructure<E> structure5.AbstractLinear<E> structure5.AbstractStack<E> structure5.StackList<E>
public class StackList<E>
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 = newStackList()
; 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(E 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. |
E |
get()
Get a reference to the top value in the stack. |
Iterator<E> |
iterator()
Returns an iterator for traversing the structure. |
E |
remove()
Remove a value from the top of the stack. |
int |
size()
Determine the number of elements in the stack. |
String |
toString()
Construct a string representation of the stack. |
Methods inherited from class structure5.AbstractStack |
---|
getFirst, peek, pop, push |
Methods inherited from class structure5.AbstractLinear |
---|
remove |
Methods inherited from class structure5.AbstractStructure |
---|
contains, elements, hashCode, isEmpty, values |
Methods inherited from class java.lang.Object |
---|
equals, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface structure5.Stack |
---|
getFirst, peek, pop, push |
Methods inherited from interface structure5.Structure |
---|
contains, elements, isEmpty, remove, values |
Constructor Detail |
---|
public StackList()
Method Detail |
---|
public void clear()
clear
in interface Structure<E>
public boolean empty()
empty
in interface Linear<E>
empty
in interface Stack<E>
empty
in class AbstractLinear<E>
AbstractStructure.isEmpty()
public Iterator<E> iterator()
Structure
iterator
in interface Iterable<E>
iterator
in interface Structure<E>
AbstractIterator
,
Iterator
,
Enumeration
,
Structure.elements()
public E get()
get
in interface Linear<E>
get
in interface Stack<E>
public void add(E value)
add
in interface Linear<E>
add
in interface Stack<E>
add
in interface Structure<E>
item
- The value to be added.AbstractStack.push(E)
public E remove()
remove
in interface Linear<E>
remove
in interface Stack<E>
AbstractStack.pop()
public int size()
size
in interface Linear<E>
size
in interface Stack<E>
size
in interface Structure<E>
public String toString()
toString
in class Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |