Sorting algorithms/Comb sort: Difference between revisions

m
Line 622:
</pre>
=={{header|Elena}}==
ELENA 3.4.x :
<lang elena>import extensions.;
import system'math.;
import system'routines.;
extension op
{
combSort()
[{
var list := self clone.clone();
real gap := list length.Length;
bool swaps := true.;
while ((gap > 1) || (swaps))
[{
gap /= 1.247330950103979r.;
if (gap<1) [{ gap := 1 ].};
int i := 0.;
swaps := false.;
while (i + gap roundedInt.RoundedInt < list length.Length)
[{
int igap := i + gap roundedInt.RoundedInt;
if (list[i] > list[igap])
[{
list .exchange(i,igap).;
swaps := true
].};
i += 1
].}
].};
^ list
]}
}
public program()
{
[
var list := (new int[]{3, 5, 1, 9, 7, 6, 8, 2, 4 ).};
console .printLine("before:", list).asEnumerable());
console .printLine("after :", list .combSort().asEnumerable())
]}</lang>
{{out}}
<pre>
Anonymous user