Question: 1 import java.util.*; public class LinkedList 4 5 public Node header; public LinkedList() header = null; public final Node Search(int key) Node current = header;




1 import java.util.*; public class LinkedList 4 5 public Node header; public LinkedList() header = null; public final Node Search(int key) Node current = header; while (current != null && current.item != key) current = current.link; return current; public final void Append(int newItem) Node newNode = new Node(newItem); newNode.link = header; header = newNode; public final Node Remove() Node x = header; if (header l= null) header - header.link; return x; public final Node searchPrevious(int key) if (header == null) return header; else Node current = header; while (!(current. link == null) && (current. link.ite! current = current. link; return current; public final void Insert(int newItem, int prekey), PS.co Node current; Node newNode = new Node(newItem); current = Search(prekey); if (current == null) System.out.println("there is no such prekey!"); else 66 newNode.link - current.link; current. link = newNode; public final void Delete(int key) if (header == null) // The list is empty! System.out.println("The list is empty!"); else if (header.item == key) // header to be deleted. header = header.link; else Node p = searchPrevious (key); . if (p. link == null) System.out.println("There is no such item!"); else p.link = p.link.link; public final void ShowLinkedList() if (header == null) System.out.println("The list is empty!"); else Node current - header System.out.printf("N1$$->", current. Item while (1(current. link == null)) current = current. link; System.out.printf("%1$s->", current. item); System.out.printf("null"); System.out.printf("%1$->", current. item); 114 System.out.printf("null"); System.out.println(); 116 117 118 public final void PrintList() 119 if (header == null) 122 ? System.out.println("The list is empty!"); else Node current = header; System.out.println(current.item); while (!(current. link == null)) current = current. link; System.out.println(current.item); 131 132 133 134 135 136 AO 6. (20) Use LinkedList as a reference, add the following operations in the class LinkedList; a) Find the average data values of the linked list. b) Find the node with largest key, and then delete the node. (Note, you must return the node, not just the largest key) c) Test above two operations in the Main method. (display the average of the data values of the linked list, the largest key, the linked list before and after deleting the node with the largest key
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
