What's the most elegant way of implementing insertion sort with Java?
public static int[] doInsertionSort(int[] input){
int temp;
for (int i = 1; i < input.length; i++) {
for(int j = i ; j > 0 ; j--){
if(input[j] < input[j-1]){
temp = input[j];
input[j] = input[j-1];
input[j-1] = temp;
}
}
}
return input;
}
>>62362563sort();
>>62362563
That's not insertion sort you retard
>>62362563
Need help on your homework I see
>>62362563
>java
>using arrays
litterally why? these exercises are useful if you do that in C. doing that in java leads to bad design and a lot of awful things. keep in mind that the libraries methods are often implemented in C or C++ so are faster and more efficent than every line of code you could do except you use a very efficent native method