public class IndexedStack<T>
extends java.lang.Object
implements java.lang.Iterable<T>
Stack in the few places where this functionality is
needed.
The stack is iterable, and iteration is in bottom-to-top order (like Java, but unlike a C# stack where iteration is top-to-bottom)
| Constructor and Description |
|---|
IndexedStack()
Create an empty stack with a default initial space allocation
|
IndexedStack(int size)
Create an empty stack with a specified initial space allocation
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(T value)
Search for an item on the stack
|
T |
get(int i)
Get the item at position N in the stack, without changing the state of the stack
|
int |
indexOf(T value)
Search for an item on the stack, starting from the bottom
|
boolean |
isEmpty()
Ask if the stack is empty
|
java.util.Iterator<T> |
iterator()
Iterate the stack in bottom to top order
|
T |
peek()
Get the item on the top of the stack, without changing the state of the stack
|
T |
pop()
Get the item on the top of the stack, and remove it from the stack
|
void |
push(T item)
Add an item to the top of the stack
|
void |
set(int i,
T value)
Overwrite the item at position N in the stack
|
int |
size()
Get the current height of the stack
|
public IndexedStack()
public IndexedStack(int size)
size - the number of entries to be allocatedpublic int size()
public boolean isEmpty()
public void push(T item)
item - the item to be addedpublic T peek()
java.util.EmptyStackException - if the stack is emptypublic T pop()
java.util.EmptyStackException - if the stack is emptypublic T get(int i)
i - the position of the required item, where the first item counting from
the bottom of the stack is position 0 (zero)java.lang.IndexOutOfBoundsException - if {code i} is negative, or greater than or equal to the stack sizepublic void set(int i,
T value)
i - the position of the required item, where the first item counting from
the bottom of the stack is position 0 (zero)value - the item to be put at the specified positionjava.lang.IndexOutOfBoundsException - if {code i} is negative, or greater than or equal to the stack sizepublic boolean contains(T value)
value - the item being soughtpublic int indexOf(T value)
value - the item being soughtvalue,
or -1 if no such item is foundCopyright (c) 2004-2022 Saxonica Limited. All rights reserved.