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

60.1K

Verified Solution

Question

Programming

Code 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.2 Ratings (906 Votes)
public class IntegerStack static class Node int data Node next private Node head public void pushint num Node n new Node    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