Question
Java - Implementing a Stack using Array Need help with adding methods to the Stack class. When correct, save the output of your program as
Java - Implementing a Stack using Array
Need help with adding methods to the Stack class. When correct, save the output of your program as an output.txt text file, saved in the BlueJ project folder.
A Tester class is also given, that tests the Stack methods. Tester may not be altered in any way.
public class Stack { public static final int MAX = 9;
private int element[]; private int top;
public Stack() { element = new int[MAX]; top = -1; } //you must write the necessary Stack methods here }
public class Tester { public static void main() { Stack s = new Stack();
for (int x = 1; x < 6; ++x) s.push(x);
while (!s.isEmpty()) System.out.println(s.pop());
//test empty stack error s.pop(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started