|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgenerics.Stack<T>
public class Stack<T>
This Stack class represents a last-in-first-out (LIFO) stack of objects. The usual push and pop operations are provided, as well as a method to peek at the top item on the stack, and a method to test for whether the stack is empty. When a stack is first created, it contains no items.
Field Summary | |
---|---|
private T[] |
data
The array into which the objects of the stack are stored. |
private static int |
MAX_SIZE
The default capacity of this stack. |
private int |
size
The number of objects in this stack. |
Constructor Summary | |
---|---|
Stack()
Constructs a new Stack with capacity for 100 objects |
|
Stack(int size)
Constructs a new Stack with capacity specified by user |
Method Summary | |
---|---|
int |
getSize()
Returns the number of objects on the stack. |
boolean |
isEmpty()
Tests if this stack is empty. |
boolean |
isFull()
Tests if this stack is full. |
T |
peek()
Returns the object at the top of this stack without removing it. |
T |
pop()
Removes and returns the object at the top of this stack. |
void |
push(T x)
Pushes an object onto the top of this stack. |
java.lang.String |
toString()
Returns the current state of this stack. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private T[] data
private int size
private static final int MAX_SIZE
Constructor Detail |
---|
public Stack()
public Stack(int size)
size
- the size of the StackMethod Detail |
---|
public int getSize()
getSize
in interface StackADT<T>
public java.lang.String toString()
toString
in class java.lang.Object
public void push(T x) throws StackFullException
push
in interface StackADT<T>
x
- The object to be stored onto the stack.
StackFullException
- - if this stack is fullpublic T pop() throws StackEmptyException
pop
in interface StackADT<T>
StackEmptyException
- - if this stack is fullpublic T peek() throws StackEmptyException
peek
in interface StackADT<T>
StackEmptyException
- - if this stack is fullpublic boolean isEmpty()
isEmpty
in interface StackADT<T>
public boolean isFull()
isFull
in interface StackADT<T>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |