Sorting algorithms/Insertion sort: Difference between revisions

Cleaned D code
(Undo revision 101335 by 208.80.119.67 (talk) — For this task, I think it is more to the point to have the algorithm)
(Cleaned D code)
Line 318:
 
=={{header|D}}==
<lang d>import std.stdio:, writeflnstd.algorithm;
 
void insertionSort(TRange)(T[]Range Adata) {
forforeach (int i =; 1; i <.. Adata.length; i++) {
Tauto value = Adata[i];
int j = i - 1;
while (j >= 0 && Adata[j] > value) {
Adata[j + 1] = Adata[j];
j = j - 1-;
}
Adata[j + 1] = value;
}
}
 
void main() {
auto a1array = [428, 6544, 246, -3124, 019, 992, 217, 8311, 78225, 14];
insertionSort(a1array);
writeflnwriteln(a1array);
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);
}</lang>
Output:
<pre>[2, 4, 11, 17, 19, 24, 25, 28, 44, 46]</pre>
 
=={{header|E}}==
{{Lines_too_long}}
Anonymous user