public class Stack<T>
extends java.util.AbstractList<T>
Stack
, but is not synchronized.Modifier and Type | Field and Description |
---|---|
private int |
changes
The change counter.
|
private java.lang.Object[] |
data
The stack data.
|
private int |
internalLength
The internal length of the data.
|
private int |
size
The stack size.
|
Constructor and Description |
---|
Stack()
Create a new instance of an empty stack.
|
Modifier and Type | Method and Description |
---|---|
void |
addAll(Stack<T> stack)
Add all elements of the specified stack on top of the current stack.
|
void |
clear()
Clear the stack.
|
boolean |
contains(java.lang.Object val)
Check if the stack contains the specified value.
|
T |
elementAt(int idx)
Get the value at the specified index.
|
boolean |
empty()
Check if the stack is empty.
|
T |
get(int idx)
Get the value at the specified index.
|
boolean |
isEmpty()
Check if the stack is empty.
|
java.util.Iterator<T> |
iterator()
Obtain an iterator over the
data . |
java.util.ListIterator<T> |
listIterator(int idx)
Obtain an iterator over the
data , starting from the specified index. |
T |
peek()
Return the top of the stack, without removing it.
|
T |
pop()
Remove the top of the stack.
|
void |
push(T elem)
Add an element to the top of the stack.
|
private void |
resize()
|
T |
set(int idx,
T val)
Set the stack at the given index to the specified value.
|
void |
setElementAt(T val,
int idx)
Set the stack at the given index to the specified value.
|
int |
size()
Get the stack size.
|
add, add, addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, remove, removeRange, subList
addAll, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
private int internalLength
private int size
private java.lang.Object[] data
size
index.private int changes
public void push(T elem)
public T peek()
java.util.EmptyStackException
- If the stack is empty.public T pop() throws java.util.EmptyStackException
java.util.EmptyStackException
- If the stack is empty.public int size()
public boolean empty()
public boolean isEmpty()
public T get(int idx)
public T elementAt(int idx)
idx
- The index value.public void setElementAt(T val, int idx)
val
- The value to set.idx
- The index in the current stack.public void addAll(Stack<T> stack)
stack
- The stack to merge.public boolean contains(java.lang.Object val)
null
values are allowed.
public java.util.ListIterator<T> listIterator(int idx)
data
, starting from the specified index.public void clear()
private void resize()