|
net.datastructures - version 5.0 | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.datastructures.NodeStack<E>
public class NodeStack<E>
Implementation of the stack ADT by means of a singly linked list.
Node
Field Summary | |
---|---|
protected int |
size
|
protected Node<E> |
top
|
Constructor Summary | |
---|---|
NodeStack()
Creates an empty stack. |
Method Summary | |
---|---|
boolean |
isEmpty()
Return whether the stack is empty. |
static void |
main(String[] args)
Test program that performs a series of operations on on a stack and prints the operation performed, the returned element and the content of the stack after each operation. |
E |
pop()
Remove the top element from the stack. |
void |
push(E elem)
Insert an element at the top of the stack. |
int |
size()
Return the number of elements in the stack. |
static void |
status(Stack S,
String op,
Object element)
Prints information about an operation and the stack. |
E |
top()
Inspect the element at the top of the stack. |
String |
toString()
Returns a string representation of the stack as a list of elements, with the top element at the end: [ ... , prev, top ]. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Node<E> top
protected int size
Constructor Detail |
---|
public NodeStack()
Method Detail |
---|
public int size()
Stack
size
in interface Stack<E>
public boolean isEmpty()
Stack
isEmpty
in interface Stack<E>
public void push(E elem)
Stack
push
in interface Stack<E>
elem
- to be inserted.public E top() throws EmptyStackException
Stack
top
in interface Stack<E>
EmptyStackException
- if the stack is empty.public E pop() throws EmptyStackException
Stack
pop
in interface Stack<E>
EmptyStackException
- if the stack is empty.public String toString()
toString
in class Object
public static void status(Stack S, String op, Object element)
op
- operation performedelement
- element returned by the operationpublic static void main(String[] args)
|
net.datastructures - version 5.0 | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |