Program in Java Create a stack class to store integers and implement following methods: 1- void push(int num):...

60.1K

Verified Solution

Question

Programming

Program in Java

Create a stack class to store integers and implement followingmethods:

1- void push(int num): This method will push an integer to thetop of the stack.

2- int pop(): This method will return the value stored in thetop of the stack. If the stack is empty this method will return-1.

3- void display(): This method will display all numbers in thestack from top to bottom (First item displayed will be the topvalue).

4- Boolean isEmpty(): This method will check the stack and if itis empty, this will return true, otherwise false.

Answer & Explanation Solved by verified expert
4.4 Ratings (617 Votes)
class Stack final int MAX 100 private int top private int a new intMAX Maximum size of Stack private int min constructer calls when the object is created Stack top 1 initialize top value    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students