Jump to content

Sorting algorithms/Comb sort: Difference between revisions

(Added Julia language)
Line 620:
sorted:
-7 1 2 5 7 95 99
</pre>
=={{header|Elena}}==
ELENA 3.2.1 :
<lang elena>import extensions.
import system'math.
import system'routines.
 
extension $op
{
combSort
[
var list := self clone.
real gap := list 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 < list length)
[
int igap := i + gap roundedInt.
if (list[i] > list[igap])
[
list exchange(i,igap).
swaps := true
].
i += 1
].
].
 
^ list
]
}
 
program =
[
var list := (3, 5, 1, 9, 7, 6, 8, 2, 4 ).
console printLine("before:", list).
console printLine("after :", list combSort).
].</lang>
{{out}}
<pre>
before:3,5,1,9,7,6,8,2,4
after :1,2,3,4,5,6,7,8,9
</pre>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.