Could you provide feedback for this code? For arrays of length 2, is it more efficient not to use a sorting algorithm?
package insertion.sort;
import java.util.Arrays;
public class InsertionSort {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int[] testArr = {-10, -5, 100, 51, 6, 50};
insertionSort(testArr);
System.out.println(Arrays.toString(testArr));
}
public static void insertionSort(int[] arr) {
for(int i = 1; i < arr.length; i++) {
int temp = arr[i];
int j;
for(j = i; j > 0 && arr[j-1] > temp; j--)
arr[j] = arr[j-1];
arr[j] = temp;
}
}
}
By the way, I've noticed "quicksort" is spelt all as one word, but "insertion sort" is spelt as two. Is that right? Would anyone ever say "quicksort sort"?