Check if the current element is not same as the element at index arr [ i ] - 1 , then swap
if ( arr [ i ] != arr [ arr [ i ] - 1 ] ) { t = arr [ i ] ; arr [ i ] = arr [ arr [ i ] - 1 ] ; arr [ t - 1 ] = t ; }