Sorting algorithms/Insertion sort: Difference between revisions

m (removed excess whitespace)
Line 27:
(defun insertion-sort (list)
(reduce #'insert list :initial-value nil))
 
 
=={{header|D}}==
import std.stdio;
void insertionSort(T)(T[] A) {
for(int i = 1; i < A.length; i++) {
T value = A[i];
int j = i - 1;
while (j >= 0 && A[j] > value) {
A[j + 1] = A[j];
j = j - 1;
}
A[j+1] = value;
}
}
void main() {
auto a1 = [4, 65, 2, -31, 0, 99, 2, 83, 782, 1];
insertionSort(a1);
writefln(a1);
auto a2 = [4.0,65.0,2.0,-31.0,0.0,99.0,2.0,83.0,782.0,1.0];
insertionSort(a2);
writefln(a2);
}
 
=={{header|Haskell}}==
Anonymous user