Sorting without comparison of elements | Java program to sort an array without comparison operator . ; Represents node of a doubly linked list ; Count of elements in given range ; Count frequencies of all elements ; Traverse through range . For every element , print it its count times . ; Driver Code
import java . util . * ; class Node { static void sortArr ( int arr [ ] , int n , int min , int max ) { int m = max - min + 1 ; int [ ] c = new int [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { c [ arr [ i ] - min ] ++ ; } for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < c [ i ] ; j ++ ) { System . out . print ( ( i + min ) + " ▁ " ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 10 , 1 , 4 , 4 , 100 , 0 } ; int min = 0 , max = 100 ; int n = arr . length ; sortArr ( arr , n , min , max ) ; } }