Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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; } } 

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

Do some organizations fit into more than one category?

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago