Package org.codelibs.jhighlight.fastutil
Interface Stack<K>
-
- All Known Subinterfaces:
CharStack
- All Known Implementing Classes:
AbstractCharList
,AbstractCharList.CharSubList
,AbstractObjectList
,AbstractObjectList.ObjectSubList
,CharArrayList
,ObjectArrayList
public interface Stack<K>
A stack.A stack must provide the classical
push(Object)
andpop()
operations, but may be also peekable to some extent: it may provide just thetop()
function, or even a more powerfulpeek(int)
method that provides access to all elements on the stack (indexed from the top, which has index 0).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
isEmpty()
Checks whether the stack is empty.K
peek(int i)
Peeks at an element on the stack (optional operation).K
pop()
Pops the top off the stack.void
push(K o)
Pushes the given object on the stack.K
top()
Peeks at the top of the stack (optional operation).
-
-
-
Method Detail
-
push
void push(K o)
Pushes the given object on the stack.- Parameters:
o
- the object that will become the new top of the stack.
-
pop
K pop()
Pops the top off the stack.- Returns:
- the top of the stack.
- Throws:
NoSuchElementException
- if the stack is empty.
-
isEmpty
boolean isEmpty()
Checks whether the stack is empty.- Returns:
- true if the stack is empty.
-
top
K top()
Peeks at the top of the stack (optional operation).- Returns:
- the top of the stack.
- Throws:
NoSuchElementException
- if the stack is empty.
-
peek
K peek(int i)
Peeks at an element on the stack (optional operation).- Returns:
- the
i
-th element on the stack; 0 represents the top. - Throws:
IndexOutOfBoundsException
- if the designated element does not exist..
-
-