早教吧作业答案频道 -->其他-->
对一组无序数据,①设计直接插入排序算法;②再对得到的有序序列进行折半查找.
题目详情
对一组无序数据,①设计直接插入排序算法;②再对得到的有序序列进行折 半查找.
▼优质解答
答案和解析
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
看了 对一组无序数据,①设计直接插...的网友还看了以下:
阅读儿歌,完成练习(二年级)反义词,一对一对,字数相等对义相反.你说直,我说弯,安全可以对危险.你说 2020-03-31 …
一道简单地理计算题问题大概是:已知两地的相对温度最高点与最低点温度相差5℃,依据垂直递减率,每上升 2020-05-24 …
关键信息基础设施的运营者违反《中华人民共和国网络安全法》第三十七条规定,在境外存储网络数据,或者向境 2020-05-31 …
求大神给鉴定一下这个屋里数据对不对,最好给出详细步骤和说明竖直平面内的圆运动(1)“绳”类:最高点 2020-06-26 …
这个辩论题能找哪些相关典例,名人名言,观点,论据,否定对方观点,论据我们要参加一个辩论比赛,我方的 2020-07-13 …
如果三角形三边满足a平方+b平方=c平方,那么这是直角三角形.这显然是对的它的逆命题到底对不对呢? 2020-07-21 …
阅读下面的资料,根据情境要求答题。热点调查阅读下列表格,写出你出的调查结论,并谈谈你对就读职业中专( 2020-11-20 …
直角三角形的三边关系?30度所对直角边是斜边的一半吧?》!30度的直角三角形3边比不是3:4:5吧? 2021-01-22 …
等腰三角形有一条对称轴这句话对不对本题原样:以下语句哪个是错的?A,等腰三角形有一条对称轴B,直线是 2021-02-02 …
下面的四个句子分别是两副对联,请你根据对偶的知识把它们重新组合起来.1踏雪寻梅圆下面的四个句子分别是 2021-02-05 …