public class ColumnArrayBasedStack extends java.lang.Object implements StackInterface
This class provides an implementation of a stack storing integers: the elements are stored in a given column (chosen by the user) of an already existing array A:
The array A is assumed to be "ideally" subdivided into columns
Constructor and Description |
---|
ColumnArrayBasedStack(int[] A,
int column,
int nColumns,
int size)
Initialize a stack using an existing T: the elements will be stored in the i-th column of the array
|
Modifier and Type | Method and Description |
---|---|
boolean |
isEmpty()
Check whether the stack is empty
|
int |
pop()
Removes the value at the top of this stack and returns that value as the value of this function.
|
void |
push(int value)
Pushes a value onto the top of this stack.
|
void |
reset()
Reset the array: all elements are removed (set to 0)
|
int |
size()
Returns the numbers of elements stored in the stack.
|
int |
top()
Returns the value at the top of this stack (with deletion).
|
java.lang.String |
toString()
Returns a string representing the elements stored in the stack
|
public ColumnArrayBasedStack(int[] A, int column, int nColumns, int size)
column
- the index of the column where the values will be storedA
- input array, ideally subdivided into columnsnColumns
- number of columns of the array Asize
- maximal number of elements to be stored into the stackpublic void push(int value)
push
in interface StackInterface
public int pop()
pop
in interface StackInterface
public int top()
top
in interface StackInterface
public int size()
size
in interface StackInterface
public boolean isEmpty()
isEmpty
in interface StackInterface
public void reset()
reset
in interface StackInterface
public java.lang.String toString()
toString
in class java.lang.Object