Maximum occurring character in a linked list | Link list node ; counting the frequency of current element p . data ; if current counting is greater than max ; Push a node to linked list . Note that this function changes the head ; Start with the empty list ; this will create a linked list of character " geeksforgeeks "
class Node { constructor ( ) { this . data = ' ' ; this . next = null ; } } ; var head_ref = null ; function maxChar ( head ) { var p = head ; var max = - 1 ; var res = ' ' ; while ( p != null ) { var q = p . next ; var count = 1 ; while ( q != null ) { if ( p . data == q . data ) count ++ ; q = q . next ; } if ( max < count ) { res = p . data ; max = count ; } p = p . next ; } return res ; } function push ( new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; head_ref = new_node ; } head_ref = null ; var str = " " ; var st = str . split ( ' ' ) ; var i ; for ( i = 0 ; i < st . length ; i ++ ) push ( st [ i ] ) ; document . write ( maxChar ( head_ref ) ) ;