Question: public class Link { private E e; // the element contained in this linked list private Link next; // the next element of the linked

 public class Link { private E e; // the element contained in this linked list private Link next; // the next element of the linked list public Link(E e, Link n) { this.e = e; this.next = n; } /** * Method to set the element */ public void setElement(E e) { this.e = e; } /** * Method to set the next linked list element */ public void setNext(Link e) { this.next = e; } /** * Method to get the element. */ public E getElement() { return this.e; } /** * Method to get the next linked list element */ public Link getNext() { return this.next; } } 

 public class Link { private E e; // the element contained

in this linked list private Link next; // the next element of

In the Link.java, you will see an implementation of Link class as described in the lecture. In this lab, you will implement a class called StackLinkedList.java. The class should use a generic (StacklinkedList) to constrain the types that can be put into the linked list. This class should have the following attributes and methods that implement a linked list: a head and tail reference to the beginning and end of the linked list a constructor that initialises an empty linked list isEmpty() that returns true if there are no elements in the stack and false otherwise. Your linked list should also have the following methods: push(E item): Pushes an item onto the top of this stack. The method should throw NullPointerException if a null element is sent as a parameter. T pop(): removes the object at the top of this stack and returns that object as the value of this function. The method should throws a NoSuchElementException If the stack is empty. T peek (): looks at the object at the top of this stack without removing it from the stack. The method should throws a NoSuchElementException If the stack is empty. Implement this Stack linked list inside StackLinkedList.java. Create the Test.java class, and create stack link lists of type Integer and String. Use the instances to test the imple- mentation of the stack linked list. In your main method, write the following code, StacklinkedList strs = new StacklinkedList (); StacklinkedList ints = new StacklinkedList (); ints. push ("Hi there.''); Please explain why this code does not compile

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!