How to sort an array by (smallest, largest, second smallest, second, largest) etc?

Posted by Binka on Stack Overflow See other posts from Stack Overflow or by Binka
Published on 2013-07-01T16:11:17Z Indexed on 2013/07/01 16:21 UTC
Read the original article Hit count: 122

Filed under:

Any ideas? I can sort an array. But not in this pattern? It needs to sort by the pattern I mentioned above.

public void wackySort2(int[] nums) {

    int sign = 0;
    int temp = 0;
    int temp2 = 0;

    for (int i = 0; i < nums.length; i++) {
        for (int j = 0; j < nums.length - 1; j++) {
            if (nums[j] > nums[j + 1]) {
                temp = nums[j];
                nums[j] = nums[j + 1];
                nums[j + 1] = temp;
                //sign = 1;
                System.out.println("Something has been done");
            }
        }
    }
}

© Stack Overflow or respective owner

Related posts about java