* X more docs for C
[mascara-docs.git] / C / sorting.and.searching.cormen.algo / src / vsi.txt
blobf707b2ee51f25fa8175011810d0051ffa22b21b2
2 ' insert sort
4 Public Sub InsertSort(ByRef A() As Variant, ByVal Lb As Long, ByVal Ub As Long)
5     Dim t As Variant
6     Dim i As Long
7     Dim j As Long
9     ' sort A[Lb..Ub]
10     For i = Lb + 1 To Ub
11         t = A(i)
13         ' shift elements down until insertion point found
14         For j = i - 1 To Lb Step -1
15             If A(j) <= t Then Exit For
16             A(j + 1) = A(j)
17         Next j
19         ' insert
20         A(j + 1) = t
21     Next i
22 End Sub