~ Create an array.
~ One By One place the character on array on based on ASCII Value .
~ then, check the value of every index and find greater value/Occurence of Character.
public class LinkedlistOperation { Node head; class Node{ int data; Node next; Node(int d){ data =d; next = null; } }
public void OccurrenceNumber(){ Node current= head; int arr[] = new int[256]; while(current!=null){ (arr[current.data])++; current =current.next; } System.out.println("Occurrence of all character are :"); for(int i=0;i<256;i++){ if(arr[i]>0){ System.out.println(i+":" +arr[i]+" "); } } }
OUTPUT :public static void main(String ...args){ LinkedlistOperation list = new LinkedlistOperation(); list.push(1); list.push(1); list.push(3); list.push(4); list.push(2); list.push(2); list.push(15); list.push(20); list.push(1); list.push(1); list.push(3); list.push(4); list.push(5); list.OccurrenceNumber() }
Occurence of all Character are : 1:4 2:2 3:2 4:2 5:1 15:1 20:1