Here you can find the source of insertionSort(int[] input)
Parameter | Description |
---|---|
input | a parameter |
public static int[] insertionSort(int[] input)
//package com.java2s; //License from project: Apache License public class Main { /**// w w w.ja v a 2 s . co m * 1 for j = 2 to A.length * 2 key = A[j] * // Insert A[j] into the sorted sequence A [1 .. j-1]. * 3 i = j - 1 * 4 while i > 0 and A[i] > key * 5 A[i+1] = A[i] * 6 A[i] = key * 7 i-- * * @param input * @return */ public static int[] insertionSort(int[] input) { for (int j = 1; j < input.length; j++) { int key = input[j]; int i = j - 1; while (i >= 0 && input[i] > key) { input[i + 1] = input[i]; input[i] = key; i--; } } return input; } }