Sorting algorithms/Shell sort: Difference between revisions

Added a V implementation
(Added a V implementation)
Line 2,881:
PRINT
RETURN</lang>
 
=={{header|Vlang}}==
<lang vlang>fn shell(arr mut []int, n int) {
mut j := 0
for h := n; h /= 2; {
for i := h; i < n; i++ {
t := arr[i]
for j = i; j >= h && t < arr[j - h]; j -= h {
arr[j] = arr[j - h]
}
arr[j] = t
}
}
}
 
fn main() {
mut arr := [4, 65, 2, -31, 0, 99, 2, 83, 782, 1]
n := arr.len
println('Input: ' + arr.str())
shell(mut arr, n)
println('Output: ' + arr.str())
}</lang>
{{out}}
<pre>Input: [4, 65, 2, -31, 0, 99, 2, 83, 782, 1]
Output: [-31, 0, 1, 2, 2, 4, 65, 83, 99, 782]</pre>
 
=={{header|Whitespace}}==
Anonymous user