summaryrefslogtreecommitdiff
path: root/260/DEPENDENCIES/insertion_sort.sci
blob: d6b5f5d32212cb49eb75eb1b5f9b8d29e92a5ec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function A = insertion_sort(A)
    n = length(A);

for(i = 2:n)
    t = A(i);
    j = i;
    while((j > 1) & (A(j-1) > t))
        A(j) = A(j-1);
        j = j-1;
    end
    A(j) = t;
end

endfunction