Question: java. Complete the code that is at the bottom. For this problem, assume that MyLinkedList uses a circular doubly-linked list with a dummy head node

java. Complete the code that is at the bottom. For this problem, assume that MyLinkedList uses a circular doubly-linked list with a dummy head node as shown in the following diagrams. Recall that the size data field is declared by the MyAbstractList class and has protected access.java. Complete the code that is at the bottom. For this problem,

  1. public class MyLinkedList extends MyAbstractList {
  2. private Node head;
  3. /** Create a default list */
  4. public MyLinkedList() {
  5. head = new Node(null);
  6. head.prev = head;
  7. head.next = head;
  8. }
  9. various methods
  10. private static class Node {
  11. E element;
  12. Node prev;
  13. Node next;
  14. public Node(E element) {
  15. this.element = element;
  16. }
  17. }
  18. }

Complete the implementation of the addNodes method below. The method receives an array of Node objects in the parameter, and then adds all the Node objects from the nodes array to the linked-list.

Your algorithm should require no more than O(n) time.

For instance, consider the list shown in the above diagram, with [Able, Baker, Jones, Smith, Wilson] currently in the list.

You have an array of Nodes as follows:

Node[] nodes = [Tom, Kate, Steve];

Calling addNodes(nodes) will update the current linked-list as [Able, Baker, Jones, Smith, Wilson, Tom, Kate, Steve]

Be clear and concise in your code. You should consider both cases, where the linked-list may or may not be initially empty. Do not forget to update size.

  1. /** Adds to the linked-list all the Node objects from the nodes array **/
  2. public void addNodes(Node[] nodes) {
  3. // YOUR CODE GOES HERE
  4. }

\\

(a) listHead -:| atve .... 1=sker.... 1-1.1 10.... 1=1/sman.... -.wson. Dummy head node (b) listHead 1. public class MyLinkedList extends MyAbstractList { 2. private Node head; 3. /** Create a default list */ 4. public MyLinkedList() { 5. head = new Node(null); 6. head.prev = head; 7. head.next = head; 8. } 9. 10 ... various methods ... 11. 12. private static class Node {

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!