public class Node { public String data; public Node next; public Node(String data, Node next) { this.data = data; this.next = next; } } public class LinkedList { private Node rear; // pointer to last node of CLL ... }The class keeps a circular linked list, with a rear pointer to the last node.
Implement the following method in the LinkedList class, to delete the first occurrence of a given item from the linked list. The method returns true if the item is deleted, or false if the item is not found.
public boolean delete(String target) { /* COMPLETE THIS METHOD */ }
public boolean addAfter(String newItem, String afterItem) { /* COMPLETE THIS METHOD */ }
A doubly linked list (DLL) is a linked list with nodes that point both forward and backward. Here's an example:
3 <---> 5 <---> 7 <---> 1Here's a DLL node definition:
public class DLLNode { public String data; public DLLNode prev, next; public DLLNode(String data, DLLNode next, DLLNode prev) { this.data = data; this.next = next; this.prev = prev; } }The next of the last node will be null, and the prev of the first node will be null.
Implement a method to move a node (given a pointer to it) to the front of a DLL.
// moves target to front of DLL public static DLLNode moveToFront(DLLNode front, DLLNode target) { /** COMPLETE THIS METHOD **/ }
public static DLLNode reverse(DLLNode front) { /** COMPLETE THIS METHOD **/ }
public static Node deleteAll(Node front, String target) { /* COMPLETE THIS METHOD */ }
For instance:
l1 = 3->9->12->15should result in the following:
l2 = 2->3->6->12
2->3->6->9->12->15
Assuming a Node class defined like this:
public class Node { public int data; public Node next; }
Complete the following method:
public static Node merge(Node frontL1, Node frontL2) { ... }