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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!