Using the ListNode file. Write methods called min and max thatreturn the smallest and largest values in the linked list. Thesemethods will be added to your ListNode class. For example if avariable called list stores {11, -7, 3, 42, 0, 14], the call oflist.min() should return -7 and the call of list.max() shouldreturn 42. If the list is empty, return -1. Print the returnedvalue. Write a method called insertNode that inserts a new nodeanywhere in your linked list. Display your linked list with newvalue.
public class ListNode
{
public int data;//data stored in this node
public ListNode front;//points to head node
public ListNode next; // link to next node in the list
// post: constructs a node with data 0 and null link
public ListNode() {
this(0, null);
}
// post: constructs a node with given data and null link
public ListNode(int data) {
this(data, null);
}
// post: constructs a node with given data and given link
public ListNode(int data, ListNode next) {
this.data = data;
this.next = next;
}
public String toString() {
if (front == null) {
return \"[]\";
} else {
String result = \"[\" + front.data;
ListNode current = front.next;
while (current != null) {
result += \", \" + current.data;
current = current.next;
}
result += \"]\";
return result;
}
}
// post: appends the given value to the end of the list
public void add(int value) {
if (front == null) {
front = new ListNode(value);
} else {
ListNode current = front;
while (current.next != null) {
current = current.next;
}
current.next = new ListNode(value);
}
}
// post : returns the position of the first occurrence of thegiven
// value (-1 if not found) Â Â
public void remove(int index) {
if (index == 0) {
front = front.next;
} else {
ListNode current = nodeAt(index - 1);
current.next = current.next.next;
}
}
// pre : 0 <= i < size()
// post: returns a reference to the node at the given index
public ListNode nodeAt(int index) {
ListNode current = front;
for (int i = 0; i < index; i++) {
current = current.next;
}
return current;
}
}