public class DStack
extends java.lang.Object
This stack is implemented with two arrays which contain links to next and previous elements. Each element is identified by an unique hash code that must be a value between zero and the size of the stack. All operations are performed in O(1).
A double-stack contains two piles of stacked values, the main stack and a backtracking stack. Note that the stack is only warranted to work correctly when the main stack and the backtracking stack contain disjoint sets.
Constructor and Description |
---|
DStack(int size)
Instantiates a new double-stack object
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(int node)
Returns
true if either the main stack or the backtracking
stack contain the specified node. |
boolean |
empty()
Checks if the main stack contains any nodes.
|
boolean |
emptyBack()
Checks if the backtracking stack contains any nodes.
|
int |
peek()
Returns the unique identifier of the node currently on the
top of the main stack.
|
int |
peekBack()
Returns the unique identifier of the node currently on the
top of the backtracking stack.
|
void |
pop()
Removes a node from the top of the main stack.
|
void |
popBack()
Removes a node from the top of the backtracking stack.
|
void |
push(int node)
Adds a node to the top of the main stack.
|
void |
pushBack(int node)
Adds a node to the top of the backtracking stack.
|
void |
raise(int node)
Promotes an already stacked node to the top of the main stack.
|
public DStack(int size)
size
- size of the stackpublic void push(int node)
node
- unique identifierpublic void raise(int node)
node
- unique identifierpublic void pop()
public int peek()
public boolean empty()
true
if the main stack is emptypublic void pushBack(int node)
node
- unique identifierpublic void popBack()
public int peekBack()
public boolean emptyBack()
true
if the main stack is emptypublic boolean contains(int node)
true
if either the main stack or the backtracking
stack contain the specified node.node
- unique identifiertrue
if the node is stacked