Question: Begin this lab by typing in the code for the generic stack interface. public interface Stack { public boolean isEmpty(); public void push(Any Type x);

 Begin this lab by typing in the code for the generic

Begin this lab by typing in the code for the generic stack interface. public interface Stack { public boolean isEmpty(); public void push(Any Type x); public AnyType pop(); public Any Type peek(); Create your own class that implements the Stack interface from part 1. Your stack should contain a reference to the singly linked list class you made in Lab 2 that is instantiated in the class constructor. Modify your linked list as necessary to support constant time insertions and deletions from the front of the list. Implement the push() method in your stack which will insert the given object into the front of your linked list (top of the stack). Implement the pop() method, which removes and returns the top (most recently inserted) item from the stack. Your method should return null if the stack is empty. Implement the isEmpty() method to check if the stack is empty and use it in your pop() method. Sometimes we want to know what's on the top of the stack without having to pop it off the stack. Implement the peek() method to support this functionality. Write a test program that instantiates an instance of your stack class and demonstrates that each of the required methods from the interface work. At a minimum, you should push a few objects onto the stack, check if the stack is empty, peek at the top item, and pop a few items off the stack. Begin this lab by typing in the code for the generic stack interface. public interface Stack { public boolean isEmpty(); public void push(Any Type x); public AnyType pop(); public Any Type peek(); Create your own class that implements the Stack interface from part 1. Your stack should contain a reference to the singly linked list class you made in Lab 2 that is instantiated in the class constructor. Modify your linked list as necessary to support constant time insertions and deletions from the front of the list. Implement the push() method in your stack which will insert the given object into the front of your linked list (top of the stack). Implement the pop() method, which removes and returns the top (most recently inserted) item from the stack. Your method should return null if the stack is empty. Implement the isEmpty() method to check if the stack is empty and use it in your pop() method. Sometimes we want to know what's on the top of the stack without having to pop it off the stack. Implement the peek() method to support this functionality. Write a test program that instantiates an instance of your stack class and demonstrates that each of the required methods from the interface work. At a minimum, you should push a few objects onto the stack, check if the stack is empty, peek at the top item, and pop a few items off the stack

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!