Sorting without comparison of elements | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int sortArr ( int arr [ ] , int n , int min , int max ) { int m = max - min + 1 ; vector < int > c ( m , 0 ) ; 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 ++ ) cout << ( i + min ) << " ▁ " ; } int main ( ) { int arr [ ] = { 10 , 10 , 1 , 4 , 4 , 100 , 0 } ; int min = 0 , max = 100 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sortArr ( arr , n , min , max ) ; return 0 ; }