How to complete the following code, and then use the program showed in screenshot to test it. I have also attach screenshot of the StackInterface code public class ArrayStack implements StackInterface { public static int CAPACITY = 100; private final T[] elements; private int topIndex; public ArrayStack() { } public ArrayStack(int size) { // Initialize size of elements // Initialize topIndex to -1 } public void push(T obj) { } public T top() { } public void pop() { } public boolean isEmpty() { } public boolean isFull() { } public int getStackSize() { // Return stack size, i.e., number of elements } @Override public String toString() { String s = "The stack is: "; for (int i = topIndex; i >= 0; i--) s += elements[i] + " "; return s; } }
How to complete the following code, and then use the
public class ArrayStack<T> implements StackInterface<T> {
public static int CAPACITY = 100;
private final T[] elements;
private int topIndex;
public ArrayStack() {
}
public ArrayStack(int size) {
// Initialize size of elements
// Initialize topIndex to -1
}
public void push(T obj) {
}
public T top() {
}
public void pop() {
}
public boolean isEmpty() {
}
public boolean isFull() {
}
public int getStackSize() {
// Return stack size, i.e., number of elements
}
@Override
public String toString() {
String s = "The stack is: ";
for (int i = topIndex; i >= 0; i--)
s += elements[i] + " ";
return s;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images