Sorting algorithms/Insertion sort: Difference between revisions

Content added Content deleted
(Add Nimrod)
Line 1,266: Line 1,266:
US Washington
US Washington
</pre>
</pre>

=={{header|Nimrod}}==
<lang nimrod>proc insertSort[T](a: var openarray[T]) =
for i in 1 .. <a.len:
let value = a[i]
var j = i
while j > 0 and value < a[j-1]:
a[j] = a[j-1]
dec j
a[j] = value

var a = @[4, 65, 2, -31, 0, 99, 2, 83, 782]
insertSort a
echo a</lang>
Output:
<pre>@[-31, 0, 2, 2, 4, 65, 83, 99, 782]</pre>


=={{header|Objeck}}==
=={{header|Objeck}}==