How to sort an array by (smallest, largest, second smallest, second, largest) etc?
- by Binka
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");
}
}
}
}