All Packages Class Hierarchy This Package Previous Next Index
Class structure.StackArray
java.lang.Object
|
+----structure.StackArray
- public class StackArray
- extends Object
- implements Stack
An implementation of a stack using an array.
StackArray(int)
- Construct a stack capable of holding at least size elements.
add(Object)
- Add a value to the top of the stack.
clear()
- Remove all elements from the stack.
empty()
- Determine if the stack is empty.
isEmpty()
- Determine if the stack is empty.
isFull()
- Determine if the stack is full.
peek()
- Get a reference to the top value in the stack.
pop()
- Remove a value from the top of the stack.
push(Object)
- Value is added to the top of the stack.
remove()
- Remove a value from the top of the stack.
size()
- Determine the number of elements in the stack.
toString()
- Construct a string representation of the stack.
StackArray
public StackArray(int size)
- Construct a stack capable of holding at least size elements.
- Postcondition:
- an empty stack with initial capacity of size is created
- Parameters:
- size - The maximum size of the stack.
clear
public void clear()
- Remove all elements from the stack.
- Postcondition:
- removes all elements from stack
add
public void add(Object item)
- Add a value to the top of the stack.
- Postcondition:
- adds an element to stack.
Will be next element popped if no intervening push
- Parameters:
- item - The value to be added.
- See Also:
- push
push
public void push(Object item)
- Value is added to the top of the stack.
- Postcondition:
- adds an element to stack.
will be next element popped if no intervening push
- Parameters:
- item - The value to be added.
remove
public Object remove()
- Remove a value from the top of the stack.
- Precondition:
- stack is not empty
- Postcondition:
- removes and returns the top element from stack.
- Returns:
- The value removed from the top of the stack.
- See Also:
- pop
pop
public Object pop()
- Remove a value from the top of the stack.
- Precondition:
- stack is not empty
- Postcondition:
- removes and returns the top element from stack.
- Returns:
- The value removed.
peek
public Object peek()
- Get a reference to the top value in the stack.
- Precondition:
- stack is not empty
- Postcondition:
- returns the top element (most recently pushed) from stack
- Returns:
- A reference to the top element of the top of the stack.
empty
public boolean empty()
- Determine if the stack is empty.
Provided for compatibility with java.util.Stack.empty.
- Postcondition:
- returns true iff the stack is empty
- Returns:
- True iff the stack is empty.
- See Also:
- isEmpty
size
public int size()
- Determine the number of elements in the stack.
- Postcondition:
- returns the size of the stack
- Returns:
- The number of values within the stack.
isEmpty
public boolean isEmpty()
- Determine if the stack is empty.
- Postcondition:
- returns true iff the stack is empty
- Returns:
- True iff the stack is empty.
- See Also:
- empty
isFull
public boolean isFull()
- Determine if the stack is full.
- Postcondition:
- returns true iff the stack is empty
- Returns:
- True iff there is no more room in the stack.
toString
public String toString()
- Construct a string representation of the stack.
- Postcondition:
- returns a string representation of stack
- Returns:
- A string representing the stack.
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index