private static int getMiddle(int[]a, int lowIndex, int highIndex){
        int reference=a[lowIndex];

        while (lowIndex < highIndex){

            //from right -> left
            while (lowIndex < highIndex && a[highIndex] > reference){
                highIndex--;
            }

            a[lowIndex]=a[highIndex];

            //from left -> right
            while (lowIndex < highIndex && a[lowIndex] < reference){
                lowIndex++;
            }

            a[highIndex]=a[lowIndex];

        }

        a[lowIndex]=reference;

        return lowIndex;
    }