Sorting algorithms/Insertion sort: Difference between revisions

Updated D entry
No edit summary
(Updated D entry)
Line 322:
 
=={{header|D}}==
<lang d>void insertionSort(T)(T[] data) pure nothrow {
<lang d>import std.stdio;
void insertionSort(T)(T[] data) pure nothrow {
foreach (i, value; data[1 .. $]) {
auto j = i + 1;
Line 332 ⟶ 330:
}
}
 
void main() {
<lang d> import std.stdio;
auto arrayitems = [28, 44, 46, 24, 19, 2, 17, 11, 25, 4];
insertionSort(array);
writelnitems.insertionSort(array);
writeln(items);
}</lang>
{{out}}
Output:
<pre>[2, 4, 11, 17, 19, 24, 25, 28, 44, 46]</pre>