text: Reorder an array such that sum of left half is not equal to sum of right half | C program for the above approach ; A comparator function used by qsort ; Function to print the required reordering of array if possible ; Sort the array in increasing order ; If all elements are equal , then it is not possible ; Else print the sorted array arr [ ] ; Driver Code ; Given array ; Function call
code: #include <stdio.h> NEW_LINE #include <stdlib.h> NEW_LINE int compare ( const void * a , const void * b ) { return ( * ( int * ) a - * ( int * ) b ) ; } void printArr ( int arr [ ] , int n ) { qsort ( arr , n , sizeof ( int ) , compare ) ; if ( arr [ 0 ] == arr [ n - 1 ] ) { printf ( " No STRNEWLINE " ) ; } else { printf ( " Yes STRNEWLINE " ) ; for ( int i = 0 ; i < n ; i ++ ) { printf ( " % d ▁ " , arr [ i ] ) ; } } } int main ( ) { int arr [ ] = { 1 , 2 , 2 , 1 , 3 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printArr ( arr , N ) ; return 0 ; }