repo.or.cz
/
mascara-docs.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
* X more docs for C
[mascara-docs.git]
/
C
/
sorting.and.searching.cormen.algo
/
src
/
vsi.txt
blob
f707b2ee51f25fa8175011810d0051ffa22b21b2
1
2
' insert sort
3
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
8
9
' sort A[Lb..Ub]
10
For i = Lb + 1 To Ub
11
t = A(i)
12
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
18
19
' insert
20
A(j + 1) = t
21
Next i
22
End Sub