对一组无序数据,①设计直接插入排序算法;②再对得到的有序序列进行折 半查找.

来源:学生作业帮助网 编辑:作业帮 时间:2024/07/17 08:52:57
对一组无序数据,①设计直接插入排序算法;②再对得到的有序序列进行折 半查找.
xTj@KVIkҵ$+b$Y8ƌdw]% uB$^xEP/t4T)1mWmA95WZHvry .O'+'t>͆h̎OWcvtɀ}8ex{2J^d:Hf'`u8ao!1;>Z+C5nv#RU)E=E]#ub Րs"TLǹմrq 6V#B ".wtn>xaZ%RVHV X-5p#/ϓHT+P<^&{'5?X_p_Q[v)J_nQYVF<8ɅR otRFC6p a{ 8yH B*o/"HjXi&r9ϑzتȋRS*aF?tKx

对一组无序数据,①设计直接插入排序算法;②再对得到的有序序列进行折 半查找.
对一组无序数据,①设计直接插入排序算法;②再对得到的有序序列进行折 半查找.

对一组无序数据,①设计直接插入排序算法;②再对得到的有序序列进行折 半查找.
Sub Insertion(MyArray(),ByVal nOrder As Integer)
Dim Index
Dim TEMP
Dim NextElement
NextElement = LBound(MyArray) + 1
While (NextElement LBound(MyArray) Then
If nOrder = ASCENDING_ORDER Then
If MyArray(Index) < MyArray(Index - 1) Then
TEMP = MyArray(Index)
MyArray(Index) = MyArray(Index - 1)
MyArray(Index - 1) = TEMP
Index = Index - 1
Else
Exit Do
End If
ElseIf nOrder = DESCENDING_ORDER Then
If MyArray(Index) >= MyArray(Index - 1) Then
TEMP = MyArray(Index)
MyArray(Index) = MyArray(Index - 1)
MyArray(Index - 1) = TEMP
Index = Index - 1
Else
Exit Do
End If
End If
Else
Exit Do
End If
gIterations = gIterations + 1
Loop
NextElement = NextElement + 1
gIterations = gIterations + 1
Wend
End Sub
Sub 查找(ByVal ai As Integer)
Dim i As Integer
Dim b As Boolean
i = sumax / 2
b = False
Do While Not b
If ai < a(i) Then i = i / 2
If ai > a(i) Then i = i + (i / 2)
If ai = a(i) Then b = True
Loop
If b Then MsgBox "ok"
End Sub