/*
 * @topic T02105 Algorithm: swap elements of array in place
 * @brief Main driver demo
*/
package swaptest;

public class Main {

    public static void main(String[] args) {
        int one = 1;
        int two = 2;
        int[] iarr = { one, two };
        System.out.print( "Before swap:\n" );
        System.out.print( "\n one == " + iarr[ 0 ] );
        System.out.print( "\n two == " + iarr[ 1 ] );
        System.out.println();

        Main me = new Main();
        me.swap( iarr );

        System.out.print( "After swap:\n" );
        System.out.print( "\n one == " + iarr[ 0 ] );
        System.out.print( "\n two == " + iarr[ 1 ] );
        System.out.println();
    }//main

    public void swap( int[] iarr ) {
        //int temp = iarr[0];
        //iarr[0] = iarr[1];
        //iarr[1] = temp;
        swap( iarr, 0, 1 );
    }
    public void swap( int[] iarr, int from, int to ) {
        int temp = iarr[ from ];
        iarr[ from ] = iarr[ to ];
        iarr[ to ] = temp;
    }
}//class Main