Sorting algorithms/Insertion sort: Difference between revisions
Content added Content deleted
imported>Arakov |
m (→{{header|Wren}}: Minor tidy) |
||
Line 5,215: | Line 5,215: | ||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
<syntaxhighlight lang=" |
<syntaxhighlight lang="wren">var insertionSort = Fn.new { |a| |
||
for (i in 1..a.count-1) { |
for (i in 1..a.count-1) { |
||
var v = a[i] |
var v = a[i] |
||
Line 5,227: | Line 5,227: | ||
} |
} |
||
var |
var array = [ [4, 65, 2, -31, 0, 99, 2, 83, 782, 1], [7, 5, 2, 6, 1, 4, 2, 6, 3] ] |
||
for (a in |
for (a in array) { |
||
System.print("Before: %(a)") |
System.print("Before: %(a)") |
||
insertionSort.call(a) |
insertionSort.call(a) |
||
Line 5,246: | Line 5,246: | ||
Alternatively we can just call a library method. |
Alternatively we can just call a library method. |
||
{{libheader|Wren-sort}} |
{{libheader|Wren-sort}} |
||
<syntaxhighlight lang=" |
<syntaxhighlight lang="wren">import "./sort" for Sort |
||
var |
var array = [ [4, 65, 2, -31, 0, 99, 2, 83, 782, 1], [7, 5, 2, 6, 1, 4, 2, 6, 3] ] |
||
for (a in |
for (a in array) { |
||
System.print("Before: %(a)") |
System.print("Before: %(a)") |
||
Sort.insertion(a) |
Sort.insertion(a) |