Sorting algorithms/Comb sort: Difference between revisions
Content added Content deleted
(Go solution) |
(Cleaned D code) |
||
Line 321: | Line 321: | ||
EXIT.</lang> |
EXIT.</lang> |
||
=={{header|D}}== |
=={{header|D}}== |
||
{{works with|D|2}}<br/> |
|||
{{trans|Python}} |
{{trans|Python}} |
||
<lang d>import std. |
<lang d>import std.stdio, std.algorithm; |
||
void |
void combSort(T)(T[] input) { |
||
int gap = input.length; |
int gap = input.length; |
||
bool swaps = true; |
bool swaps = true; |
||
while (gap > 1 || swaps) { |
while (gap > 1 || swaps) { |
||
gap = max(1, cast(int)(gap / 1.2473)); |
gap = max(1, cast(int)(gap / 1.2473)); |
||
swaps = false; |
swaps = false; |
||
foreach (i; 0 .. input.length - gap) |
foreach (i; 0 .. input.length - gap) |
||
Line 340: | Line 340: | ||
void main() { |
void main() { |
||
auto |
auto array = [28, 44, 46, 24, 19, 2, 17, 11, 25, 4]; |
||
combSort(array); |
|||
writeln(array); |
|||
writeln(a); |
|||
}</lang> |
}</lang> |
||
Output: |
|||
<pre>[2, 4, 11, 17, 19, 24, 25, 28, 44, 46]</pre> |
|||
=={{header|Forth}}== |
=={{header|Forth}}== |