Sorting algorithms/Insertion sort: Difference between revisions

(Added Wren)
Line 596:
}
}</lang>
 
=={{header|B4X}}==
<lang b4x>Sub InsertionSort (A() As Int)
For i = 1 To A.Length - 1
Dim value As Int = A(i)
Dim j As Int = i - 1
Do While j >= 0 And A(j) > value
A(j + 1) = A(j)
j = j - 1
Loop
A(j + 1) = value
Next
End Sub
 
Sub Test
Dim arr() As Int = Array As Int(34, 23, 54, 123, 543, 123)
InsertionSort(arr)
For Each i As Int In arr
Log(i)
Next
End Sub
</lang>
{{out}}
<pre>
23
34
54
123
123
543
</pre>
 
=={{header|BASIC}}==
Anonymous user