TypeDef keytype = Integer
Sub insertsort(n As Integer, a As *keytype)
Dim i As Integer, j As Integer
Dim x As keytype
For i = 1 To n
'整列の比較要素を定める
x = a[i]
'xよりも大きいものを右に寄せる
j = i - 1
While j >= 0 And a[j] > x
a[j + 1] = a[j]
j = j - 1
Wend
a[j + 1] = x
Next i
End Sub