Hi, I am not sure what's wrong with my code. Can you please check why it is giving me an error? In the starter file is a partial implementation of a doubly-linked list in DoublyLinkedList.java. We will write three new methods in this class to provide additional functionality. Write a method addFirst that adds a new element at the beginning of a DoublyLinkedList. Write a method addLast that adds a new element at the end of a DoublyLinkedList. Write a method removeFirst that removes and returns the first element of a DoublyLinkedList. Try to keep your implementations as simple as possible. For example, recall this definition of addFirst in the (Singly) LinkedList class: public void addFirst(E value) { head = new Node(value, head); } In the DoublyLinkedList class, you will need to keep the three instance variables head, tail, and count updated in all methods. Note that addFirst and addLast will be symmetric to each other, as will removeFirst and removeLast (provided in the starter code).
Hi, I am not sure what's wrong with my code. Can you please check why it is giving me an error?
In the starter file is a partial implementation of a doubly-linked list in DoublyLinkedList.java. We will write three new methods in this class to provide additional functionality.
-
Write a method addFirst that adds a new element at the beginning of a DoublyLinkedList.
-
Write a method addLast that adds a new element at the end of a DoublyLinkedList.
-
Write a method removeFirst that removes and returns the first element of a DoublyLinkedList.
Try to keep your implementations as simple as possible. For example, recall this definition of addFirst in the (Singly) LinkedList class:
public void addFirst(E value) { head = new Node(value, head); }
In the DoublyLinkedList class, you will need to keep the three instance variables head, tail, and count updated in all methods. Note that addFirst and addLast will be symmetric to each other, as will removeFirst and removeLast (provided in the starter code).
Trending now
This is a popular solution!
Step by step
Solved in 7 steps with 7 images