Question: Stacks are specialized lists of data that only support inserting and deleting data from one end of the list. This means that stacks are LIFO

 Stacks are specialized lists of data that only support inserting and

Stacks are specialized lists of data that only support inserting and deleting data from one end of the list. This means that stacks are LIFO data structures, where the Last In item is the First Out. This section of the lab will guide you through creating a stack using the singly linked list you made in Lab 2. 1. 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 AnyType peek(); 2. 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. 3. Implement the push() method in your stack which will insert the given object into the front of your linked list (top of the stack). 4. 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. 5. 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. 6. 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. Stacks are specialized lists of data that only support inserting and deleting data from one end of the list. This means that stacks are LIFO data structures, where the Last In item is the First Out. This section of the lab will guide you through creating a stack using the singly linked list you made in Lab 2. 1. 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 AnyType peek(); 2. 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. 3. Implement the push() method in your stack which will insert the given object into the front of your linked list (top of the stack). 4. 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. 5. 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. 6. 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!