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