Question: JavaScript I need the answer base on my code to each task blow( one by one separated) the changes is in the main each task
JavaScript
I need the answer base on my code to each task blow( one by one separated) the changes is in the main each task will be done separated, the code in the main and the run sample just all i need



this is my java code, I need it to be corrected to match the the output that's it






Lab 4: Circular Linked-List Objective(s) 1- Create Circular Linked-List in Java. 2- Deal with Circular Linked-List in case of: insertion, Deletion, searching. Tool(s)/Software Java programming language with NetBeans IDE. Description: Tail Node 2 Node 3 them item Null Linear linked list Head Tall Node 1 Node 2 Node 3 mom Circular linked list Singly Circular Linked List: It is just like the singly/linear linked list where tail node holds the address of head node so traversal can be done circular in only one direction. A. How to Create Circular Linked-List in Java: There are 3-steps approach to create Circular Linked-List in Java Step 1: Declare class for the Node - forming the structure of the node private static class Node private E element; private Node next; public Node (E e, Node n) { this.element - e: this.next = n; > public E getElement() { return this.element; 1 public Node getNext() { return this.next; > public void setNext (Node n) this.next-ni Step 2: Declare the CircularLinkedList class that includes the Node class. public cua CircularlinkedList private class Node ... 26 lines Node hoed null; Node tail null; int size = 0; public CircularLinkedmiot 0 0 Ace Mode public int size ... lines public boolean isEmpty() ... 3 lines public int first() 1...3 lines public int last() ...3 lines public void display ...14 linea GOOD //update Method: public void addFirst (int value) 1...15 lines public void addLast(int value) 1...14 lines public void addAt Pos(int pos, int value) 1...16 Display method in CircularLinkedList class: public void display() { if (isEmpty()) System.out.println("EmptyList.."); Node current - head: int i = 1; do System.out.println (ode + (i++) + ":" + current.getData()); current = current.getNext(): 1 while (current != head); Step 3: Define the object of CircularLinkedList class: CircularLinkedList myList=new CircularLinkedList (); myList.addFirst (10); myList.addFirst (20); myList.addFirst ( 30 ); myList.addFirst (40); B. Circular Linked-List Operations: 1. Traversing Circular Linked-List 2. Searching in Circular Linked-List 3. Insertion in Circular Linked-List 4. Deletion from Circular Linked-List Note: Please refer to lecture slides for the algorithms. Tasks/Assignments(s) 1. Create CircularLinkedList class. Apply all the following operations: Adition: addFirst, addLast, addAtPoistion Deletion: removeFirst, removeNode. FindNode: to find a node with specific given value. 2. Add a method rotate() to CircularLinkedList class that shift the list one node, below is the output before and after calling the method. Node 2:30 Node 3:20 Node 4 :10 runt Display List: Node 1:40 The list is shifted Display List: Node 1:30 First element: 30 Last element: 40 Node 2:20 Node 3 :10 Node 4 : 40 Deliverables(s) You are required to implement and deliver a Java program as described in the previous section. 7 package cs310_2172.linkedlist: * * @author anwar public class CircularLinkedList { Node head=null; Node tailenull; int size=0; class Node Node next; T Element: Node(T value, Node next) { this.Element = value: this next next > public Node getNext() { retum next: 3 public void setNext(Node next) { this.next next; > public TgetElemento retum Element public T getHead retum head.getElement() } public T get Tail() { retum tall.getElemento: ) public int getSize({ retum size: boolean isEmpty { ir (head == null) { return true; > else return false; } void Display if(isEmpty) { System.out.println("EmptyList."): retum; } System.out.println(" Display List: "); Node current = head; int count=1; do { System.out.print("\Node "+count+"="+current.getElement().toString(): current = current.getNext(): count++: }while (current = head); void addFirst/T Element) { Node newNode = new Node(Element, head): head=newNode; if (size=0){ newNode.next=head; tail = head: } else { tail.next=newNode: } size+ } void addLast(T Element) Node newNode = new Node(Element, head); if (size == 0) tail = newNode: head = tail tail next = newNode; > else tail.next = newNode: tail = newNode; } size++ } public void addAtPos(Te, int position) { if (position == 1) { addFirst(e): retum; } if (position size) { System.out.println("nInvalid Position (+position+"}} retum; Node newNode = new Node(e, null); Node current = head; int count = 1; while (count position) { current current.getNext(): count++; ) newNode.setNext(current.getNext()); current.setNext(newNode): size++; } int FindNode(T key) { Node current = head int counter = 1; while (current t= null) { if (current.getElement(-- key) { System.out.println("Found in position# " + counter): retum counter } counter++; current = current.getNext(): retum-1; > void removeFirst { if(isEmpty) System.out.println("Empty list"); retum head = head.getNext(): tail.setNext(head): size- if (size == 0) head =null; tail = null; void RemoveNode(T key) { Node current = head: Node prev = head; while (current.getElement() = key) { if (current.next == head) { System.out.println("Not found"); return; } prev = current current = current.next } if (current == head) { removeFirst(): } else { prev.setNext(current.getNext() size- } i void rotate() it (lisEmpty() { head = head.getNexto: E The main package cs310_2172.linkedlist: * @author anwar public class Cs310_2172LinkedList { * @param args the command line arguments 7 public static void main(String[] args) { CircularLinkedListo: } public static void CircularLinkedList() { CircularLinkedList theList = new CircularLinkedList(); theList.addFirst("10"): theList.addFirst("20"); theList.addFirst("30"); theList.addFirst("40"); theList. Display(); theList.RemoveNode("40"); theList.Display(); theList.rotate(); theList.Display(); theList.rotate(); theList.Display(); } Tasks/Assignments(s) 1. Create CircularLinkedList class. Apply all the following operations: Adition: addFirst, addLast, addAtPoistion Deletion: removeFirst, removeNode. FindNode: to find a node with specific given value. 2. Add a method rotate() to CircularLinkedList class that shift the list one node, below is the output before and after calling the method. Node 2:30 Node 3:20 Node 4 :10 run: Display List: Node 1:40 The list is shifted Display List: Node 1 30 First element: 30 Last element: 40 Node 2:20 Node 3:10 Node 4 : 40 Lab 4: Circular Linked-List Objective(s) 1- Create Circular Linked-List in Java. 2- Deal with Circular Linked-List in case of: insertion, Deletion, searching. Tool(s)/Software Java programming language with NetBeans IDE. Description: Tail Node 2 Node 3 them item Null Linear linked list Head Tall Node 1 Node 2 Node 3 mom Circular linked list Singly Circular Linked List: It is just like the singly/linear linked list where tail node holds the address of head node so traversal can be done circular in only one direction. A. How to Create Circular Linked-List in Java: There are 3-steps approach to create Circular Linked-List in Java Step 1: Declare class for the Node - forming the structure of the node private static class Node private E element; private Node next; public Node (E e, Node n) { this.element - e: this.next = n; > public E getElement() { return this.element; 1 public Node getNext() { return this.next; > public void setNext (Node n) this.next-ni Step 2: Declare the CircularLinkedList class that includes the Node class. public cua CircularlinkedList private class Node ... 26 lines Node hoed null; Node tail null; int size = 0; public CircularLinkedmiot 0 0 Ace Mode public int size ... lines public boolean isEmpty() ... 3 lines public int first() 1...3 lines public int last() ...3 lines public void display ...14 linea GOOD //update Method: public void addFirst (int value) 1...15 lines public void addLast(int value) 1...14 lines public void addAt Pos(int pos, int value) 1...16 Display method in CircularLinkedList class: public void display() { if (isEmpty()) System.out.println("EmptyList.."); Node current - head: int i = 1; do System.out.println (ode + (i++) + ":" + current.getData()); current = current.getNext(): 1 while (current != head); Step 3: Define the object of CircularLinkedList class: CircularLinkedList myList=new CircularLinkedList (); myList.addFirst (10); myList.addFirst (20); myList.addFirst ( 30 ); myList.addFirst (40); B. Circular Linked-List Operations: 1. Traversing Circular Linked-List 2. Searching in Circular Linked-List 3. Insertion in Circular Linked-List 4. Deletion from Circular Linked-List Note: Please refer to lecture slides for the algorithms. Tasks/Assignments(s) 1. Create CircularLinkedList class. Apply all the following operations: Adition: addFirst, addLast, addAtPoistion Deletion: removeFirst, removeNode. FindNode: to find a node with specific given value. 2. Add a method rotate() to CircularLinkedList class that shift the list one node, below is the output before and after calling the method. Node 2:30 Node 3:20 Node 4 :10 runt Display List: Node 1:40 The list is shifted Display List: Node 1:30 First element: 30 Last element: 40 Node 2:20 Node 3 :10 Node 4 : 40 Deliverables(s) You are required to implement and deliver a Java program as described in the previous section. 7 package cs310_2172.linkedlist: * * @author anwar public class CircularLinkedList { Node head=null; Node tailenull; int size=0; class Node Node next; T Element: Node(T value, Node next) { this.Element = value: this next next > public Node getNext() { retum next: 3 public void setNext(Node next) { this.next next; > public TgetElemento retum Element public T getHead retum head.getElement() } public T get Tail() { retum tall.getElemento: ) public int getSize({ retum size: boolean isEmpty { ir (head == null) { return true; > else return false; } void Display if(isEmpty) { System.out.println("EmptyList."): retum; } System.out.println(" Display List: "); Node current = head; int count=1; do { System.out.print("\Node "+count+"="+current.getElement().toString(): current = current.getNext(): count++: }while (current = head); void addFirst/T Element) { Node newNode = new Node(Element, head): head=newNode; if (size=0){ newNode.next=head; tail = head: } else { tail.next=newNode: } size+ } void addLast(T Element) Node newNode = new Node(Element, head); if (size == 0) tail = newNode: head = tail tail next = newNode; > else tail.next = newNode: tail = newNode; } size++ } public void addAtPos(Te, int position) { if (position == 1) { addFirst(e): retum; } if (position size) { System.out.println("nInvalid Position (+position+"}} retum; Node newNode = new Node(e, null); Node current = head; int count = 1; while (count position) { current current.getNext(): count++; ) newNode.setNext(current.getNext()); current.setNext(newNode): size++; } int FindNode(T key) { Node current = head int counter = 1; while (current t= null) { if (current.getElement(-- key) { System.out.println("Found in position# " + counter): retum counter } counter++; current = current.getNext(): retum-1; > void removeFirst { if(isEmpty) System.out.println("Empty list"); retum head = head.getNext(): tail.setNext(head): size- if (size == 0) head =null; tail = null; void RemoveNode(T key) { Node current = head: Node prev = head; while (current.getElement() = key) { if (current.next == head) { System.out.println("Not found"); return; } prev = current current = current.next } if (current == head) { removeFirst(): } else { prev.setNext(current.getNext() size- } i void rotate() it (lisEmpty() { head = head.getNexto: E The main package cs310_2172.linkedlist: * @author anwar public class Cs310_2172LinkedList { * @param args the command line arguments 7 public static void main(String[] args) { CircularLinkedListo: } public static void CircularLinkedList() { CircularLinkedList theList = new CircularLinkedList(); theList.addFirst("10"): theList.addFirst("20"); theList.addFirst("30"); theList.addFirst("40"); theList. Display(); theList.RemoveNode("40"); theList.Display(); theList.rotate(); theList.Display(); theList.rotate(); theList.Display(); } Tasks/Assignments(s) 1. Create CircularLinkedList class. Apply all the following operations: Adition: addFirst, addLast, addAtPoistion Deletion: removeFirst, removeNode. FindNode: to find a node with specific given value. 2. Add a method rotate() to CircularLinkedList class that shift the list one node, below is the output before and after calling the method. Node 2:30 Node 3:20 Node 4 :10 run: Display List: Node 1:40 The list is shifted Display List: Node 1 30 First element: 30 Last element: 40 Node 2:20 Node 3:10 Node 4 : 40