Jump to content

Sorting algorithms/Gnome sort: Difference between revisions

no edit summary
No edit summary
Line 3,808:
2/02/2010 10:19:51 AM, 3/02/2010 10:19:51 AM, 5/02/2010 10:19:51 AM</lang>
Note: All data in VBScript is of type Variant. Thus the code can sort many different types of data without code modification.
 
=={{header|Vlang}}==
{{trans|go}}
<lang vlang>fn main() {
mut a := [170, 45, 75, -90, -802, 24, 2, 66]
println("before: $a")
gnome_sort(mut a)
println("after: $a")
}
fn gnome_sort(mut a []int) {
for i, j := 1, 2; i < a.len; {
if a[i-1] > a[i] {
a[i-1], a[i] = a[i], a[i-1]
i--
if i > 0 {
continue
}
}
i = j
j++
}
}</lang>
{{out}}
<pre>before: [170, 45, 75, -90, -802, 24, 2, 66]
after: [-802, -90, 2, 24, 45, 66, 75, 170]
</pre>
 
=={{header|Wren}}==
338

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.