早教吧作业答案频道 -->其他-->
对一组无序数据,①设计直接插入排序算法;②再对得到的有序序列进行折半查找.
题目详情
对一组无序数据,①设计直接插入排序算法;②再对得到的有序序列进行折 半查找.
▼优质解答
答案和解析
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
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
看了 对一组无序数据,①设计直接插...的网友还看了以下:
将一张正方形的纸对折,再对折,经过4次对折后全打开,看看可以得到多少组平行线,多少组互相垂直的线段 2020-04-26 …
(应用题列算式)注意 :应用题要列算式 1.手工小组计划25天折10000纸鹤 实际少用了5天 实 2020-05-13 …
求160道,直接列算式那种,不要应用题. 2020-05-16 …
请直接列算式,三年级还没有学习设X、Y.一个长方形,如果宽增加4厘米,面积就增加32平方厘米,这是 2020-05-22 …
把6米长的木料平均锯成3米,要6分钟,照这样计算,如果锯成6段,需多少分钟?直接列算式就行了! 2020-05-23 …
甲乙两框共有橘子100千克,若从甲箱取出12千克放入乙箱,这时甲箱还比乙箱多4千克,求两箱原有水果 2020-05-23 …
一种商品先提价4分之1,然后又降价4分之1,现价和原来大的价格相比是提高了还是降低了?提高(或降低 2020-06-06 …
有一堆桃子,如果2个放一盘,多出一个;如果5个放一盘,多出2个;如果3个放一盘,正好放完.这些桃子 2020-06-20 …
长方形abcd的面积是16平方米,e、f都是所在边的中点.求三角形aef的面积.最好是直接列算式 2020-08-02 …
爸爸的岁数的1/3是小明的岁数,已知爸爸和小明一共是48岁,爸爸比小明大多少岁?(列算式计算)直接列 2020-11-17 …