Find the smallest digit on right side of ith digit which is greater than num [ i ] up to index ' mid '
int smallest = i + 1 ; for ( j = i + 2 ; j <= mid ; j ++ ) if ( num [ j ] > num [ i ] && num [ j ] <= num [ smallest ] ) smallest = j ;