Sorting algorithms/Insertion sort: Difference between revisions
Content added Content deleted
m (→{{header|Fortran}}: classic mistake with non-short-circuit logical operators) |
(+Stata) |
||
Line 2,779: | Line 2,779: | ||
while output = A<i>; i = ?lt(i,aSize) i + 1 :s(while) |
while output = A<i>; i = ?lt(i,aSize) i + 1 :s(while) |
||
end</lang> |
end</lang> |
||
=={{header|Stata}}== |
|||
<lang stata>mata |
|||
void insertion_sort(real vector a) { |
|||
real scalar i, j, n, x |
|||
n = length(a) |
|||
for (i=2; i<=n; i++) { |
|||
x = a[i] |
|||
for (j=i-1; j>=1; j--) { |
|||
if (a[j] <= x) break |
|||
a[j+1] = a[j] |
|||
} |
|||
a[j+1] = x |
|||
} |
|||
} |
|||
end</lang> |
|||
=={{header|Swift}}== |
=={{header|Swift}}== |
||
Using generics. |
Using generics. |