@@ -0,0 +1,1387 @@
+package ru.sort.insertsort;%0A%0Aimport org.junit.Test;%0Aimport ru.permutation.Perm0;%0A%0Aimport static org.junit.Assert.*;%0A%0Aimport static java.util.Arrays.*;%0A%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0A/**%0A * @author DKandalov%0A */%0Apublic class InsertSort7 %7B%0A    private static List%3CInteger%3E emptyList = Arrays.%3CInteger%3EasList();%0A%0A    @Test%0A    public void shouldSortList() %7B%0A        assertEquals(sort(emptyList), emptyList);%0A        assertEquals(sort(asList(1)), asList(1));%0A        assertEquals(sort(asList(1, 2)), asList(1, 2));%0A        assertEquals(sort(asList(1, 2, 3)), asList(1, 2, 3));%0A        assertEquals(sort(asList(3, 1, 2)), asList(1, 2, 3));%0A%0A        for (List%3CInteger%3E list : Perm0.perm(asList(1, 2, 3, 4, 5))) %7B%0A            assertEquals(sort(list), asList(1, 2, 3, 4, 5));%0A        %7D%0A    %7D%0A%0A    public List%3CInteger%3E sort(List%3CInteger%3E list) %7B%0A        if (list.size() %3C 2) return list;%0A%0A        for (int i = 1; i %3C list.size(); i++) %7B%0A            for (int j = i; j %3E= 1; j--) %7B%0A                if (!compareAndExchange(list, j - 1, j)) break;%0A            %7D%0A        %7D%0A        return list;%0A    %7D%0A%0A    private static boolean compareAndExchange(List%3CInteger%3E list, int pos1, int pos2) %7B%0A        if (list.get(pos1) %3C= list.get(pos2)) return false;%0A%0A        int tmp = list.get(pos1);%0A        list.set(pos1, list.get(pos2));%0A        list.set(pos2, tmp);%0A        return true;%0A    %7D%0A%7D%0A

insert sort java <<>> :)