Maximum occurring character in a linked list | C ++ program to count the maximum occurring character in linked list ; Link list node ; Storing element 's frequencies  in a hash table. ; calculating the first maximum element ; Push a node to linked list . Note that this function changes the head ; Driver program to test above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { char data ; struct Node * next ; } ; char maxChar ( struct Node * head ) { struct Node * p = head ; int hash [ 256 ] = { 0 } ; while ( p != NULL ) { hash [ p -> data ] ++ ; p = p -> next ; } p = head ; int max = -1 ; char res ; while ( p != NULL ) { if ( max < hash [ p -> data ] ) { res = p -> data ; max = hash [ p -> data ] ; } p = p -> next ; } return res ; } void push ( struct Node * * head_ref , char new_data ) { struct Node * new_node = new Node ; new_node -> data = new_data ; new_node -> next = ( * head_ref ) ; ( * head_ref ) = new_node ; } int main ( ) { struct Node * head = NULL ; char str [ ] = " skeegforskeeg " ; for ( int i = 0 ; str [ i ] != ' \0' ; i ++ ) push ( & head , str [ i ] ) ; cout << maxChar ( head ) ; return 0 ; }