## Write a program in Java to find the maximum and minimum value node from a circular linked list.

``````public class MinMax {
//Represents the node of list.
public class Node{
int data;
Node next;
public Node(int data) {
this.data = data;
}
}

//Declaring head and tail pointer as null.
public Node tail = null;

//This function will add the new node at the end of the list.
//Create new node
Node newNode = new Node(data);
//Checks if the list is empty.
//If list is empty, both head and tail would point to new node.
tail = newNode;
}
else {
//tail will point to new node.
tail.next = newNode;
//New node will become new tail.
tail = newNode;
}
}

//Finds out the minimum value node in the list
public void minNode() {
//Initializing min to initial node data
System.out.println("List is empty");
}
else {
do{
//If current node's data is smaller than min
//Then replace value of min with current node's data
if(min > current.data) {
min = current.data;
}
current= current.next;

System.out.println("Minimum value node in the list: "+ min);
}
}

//Finds out the maximum value node in the list
public void maxNode() {
//Initializing max to initial node data
System.out.println("List is empty");
}
else {
do{
//If current node's data is greater than max
//Then replace value of max with current node's data
if(max < current.data) {
max = current.data;
}
current= current.next;

System.out.println("Maximum value node in the list: "+ max);
}
}

public static void main(String[] args) {
MinMax cl = new MinMax();
//Prints the minimum value node in the list
cl.minNode();
//Prints the maximum value node in the list
cl.maxNode();
}
}
``````

Output:

``````Minimum value node in the list: 1
Maximum value node in the list: 20
``````
Author's Other questions
 Write a program to calculate the difference between the sum of the odd level and even level nodes of a Binary Tree Write a program in Java to create a doubly linked list containing n nodes How to perform quicksort in Java? How to perform merge sort in Java? How to perform Linear Search in Java? How to perform Selection Sort in Java? How to perform Binary Search in Java? How to perform Bubble Sort in Java? Can RMI and CORBA based applications interact? What is JRMP? What is the use of HTTP-tunneling in RMI? What are the steps involved to write RMI based programs? What is the purpose of stub and skeleton? What do you understand by the bean persistent property? What is the purpose of using the Java bean? What is a JavaBean? How will you load a specific locale? What is Locale? Can you write a Java class that could be used both as an applet as well as an application? What is an applet?