pop and swap
int pop [ ] = stack . pop ( ) ; int index = pop [ 0 ] , val = pop [ 1 ] ; arr [ index ] = arr [ i ] ; arr [ i ] = val ; } else stack . push ( new int [ ] { i , arr [ i ] } ) ; } else stack . push ( new int [ ] { i , arr [ i ] } ) ; }