Find minimum and maximum elements in singly Circular Linked List | structure for a node ; Function to prvar minimum and maximum nodes of the circular linked list ; check list is empty ; pointer for traversing ; initialize head to current pointer ; initialize max var value to min initialize min var value to max ; While last node is not reached ; If current node data is lesser for min then replace it ; If current node data is greater for max then replace it ; Function to insert a node at the end of a Circular linked list ; Create a new node ; check node is created or not ; insert data into newly created node ; check list is empty if not have any node then make first node it ; if list have already some node ; move firt node to last node ; put first or head node address in new node link ; put new node address into last node link ( next ) ; Function to prvar the Circular linked list ; if list is empty simply show message ; traverse first to last node ; Driver Code
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function printMinMax ( head ) { if ( head == null ) { return ; } var current ; current = head ; var min = Number . MAX_VALUE , max = Number . MIN_VALUE ; while ( current . next != head ) { if ( current . data < min ) { min = current . data ; } if ( current . data > max ) { max = current . data ; } current = current . next ; } document . write ( " " + min + " " + max ) ; } function insertNode ( head , data ) { var current = head ; var newNode = new Node ( ) ; if ( newNode == null ) { document . write ( " " ) ; return null ; } newNode . data = data ; if ( head == null ) { newNode . next = newNode ; head = newNode ; return head ; } else { while ( current . next != head ) { current = current . next ; } newNode . next = head ; current . next = newNode ; } return head ; } function displayList ( head ) { var current = head ; if ( head == null ) { document . write ( " " ) ; return ; } else { do { document . write ( current . data + " " ) ; current = current . next ; } while ( current != head ) ; } } var Head = null ; Head = insertNode ( Head , 99 ) ; Head = insertNode ( Head , 11 ) ; Head = insertNode ( Head , 22 ) ; Head = insertNode ( Head , 33 ) ; Head = insertNode ( Head , 44 ) ; Head = insertNode ( Head , 55 ) ; Head = insertNode ( Head , 66 ) ; document . write ( " " ) ; displayList ( Head ) ; printMinMax ( Head ) ;