Question: class StackX { private int maxSize; private long [] stackArray; private int top; public StackX( int s) { maxSize = s; stackArray = new long
class StackX {
private int maxSize;
private long[] stackArray;
private int top;
public StackX(int s) {
maxSize = s;
stackArray = new long[maxSize];
top = -1;
}
public void push(long j)
{
stackArray[++top] = j;
}
public long pop()
{
return stackArray[top--]; }
public long peek()
{
return stackArray[top]; }
public boolean isEmpty()
{
return (top == -1); }
public boolean isFull()
{
return (top == maxSize-1); }
}
Using Stack algorithm as shown in the code above, create a main program that is capable to store 10 numbers. The program should accept a number entered from the keyboard. The user can add a number while the array is not yet full, once the array is full the program should show message that the array is full, and the user can only add another number if the user will remove a number from the array. The program should also inform the user if the array is empty.
Note: The program should have a menu as shown below and include all necessary error checking for this program.
Menu [1] Insert Number [2] Remove Number (Note: The user will enter what number to remove)
[3] Display content of the array [4] Exit Enter your choice:
Note: Make sure that the number will remove by user (The user choose the number by scanner)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
