Sorting algorithms/Comb sort: Difference between revisions

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