Write a program to sort given array according to frequency of occurrence of numbers, in ascending order.
Input (int[]) | Output (int[]) |
---|---|
{1, 4, 3, 4, 5, 4, 5} | {1, 3, 5, 5, 4, 4, 4} |
{9, 3, 9, 2, 3, 2, 1, 2, 2, 3} | {1, 9, 9, 3, 3, 3, 2, 2, 2, 2} |
{4, -1, 0, 4, -1, 0, -1} | {4, 4, 0, 0, -1, -1, -1} |
{6, 4, 6, 1, 6, 1} | {4, 1, 1, 6, 6, 6} |
class SortByOccurrenceInAscendingOrder
{ public static void main(String s[])
{
int array[] = {3, 4, 5, 0, 0, 0, 0, 0, 3, 3, 3, 5, 1, 5};
sortByOccurrence(array);
for (int n : array)
System.out.print(n + " ");
}
public static void sortByOccurrence(int[] inputArray) {
//Write code here to sort array according to occurrence of numbers in ascending order
}
//If required, write any additional methods here
}
Topic: Learn Arrays And Loops