Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Stack algorithm as shown in the code above, create a program that is capable to store 10 numbers. The program should accept a number

Using Stack algorithm as shown in the code above, create a 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:

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 this class without chinging any thing

but write the main and

the write the code remove by the user

the user get to choose what to remove from the stacl

using java eclipse

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions