Question
I need to create a class DoublyLinkedList which has a generic type E and subclasses the abstract LabTemplate class. In DoublyLinkedList, I need to implement
I need to create a class DoublyLinkedList which has a generic type E and subclasses the abstract LabTemplate class.
In DoublyLinkedList, I need to implement every abstract method defined in the LabTemplate class.
The class header for DoublyLinkedList should be as follows:
public class DoublyLinkedList
I don't need to implement the node class.
When adding an element to the head or tail of a list: create a new node with the given element, set the head or tail instance variable to the new node, set the new nodes next
and previous instance variables to the appropriate values, and increase the size instance variable.
If a node does not have a next or pervious node (for example, the last node in the linked list does not have a next node), the value of its next or pervious instance variable should be null
If the linked list is empty, the head and tail instance variables should be null
If the linked list has a single element, the head and tail instance variables should both be set to the single node. But the nodes next and previous instance variables should both be null.
When removing a node, we delink the node from the linked list. For example, if we want to remove the head node: we should get the second node in the linked list,
set that node to the head variable, set the value of the new heads previous instance variable to null, set the value of the hold heads next instance variable to null,
and get the element stored in the old head and return it.
Here is the LabTemplate class
--------------------------------------------------------
public abstract class LabTemplate
protected Node
Here is Node class
------------------------------------------------------------
public class Node
//Instance Variables private E element; private Node
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started