function to sort each row of the matrix according to the order specified by descending .
static void sortByRow ( int [ , ] mat , int n , bool descending ) { int temp = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( descending == true ) { int t = i ; for ( int p = 0 ; p < n ; p ++ ) { for ( int j = p + 1 ; j < n ; j ++ ) { if ( mat [ t , p ] < mat [ t , j ] ) { temp = mat [ t , p ] ; mat [ t , p ] = mat [ t , j ] ; mat [ t , j ] = temp ; } } } } else sortByRow ( mat , i , n ) ; } }