早教吧作业答案频道 -->其他-->
对一组无序数据,①设计直接插入排序算法;②再对得到的有序序列进行折半查找.
题目详情
对一组无序数据,①设计直接插入排序算法;②再对得到的有序序列进行折 半查找.
▼优质解答
答案和解析
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
看了 对一组无序数据,①设计直接插...的网友还看了以下:
9.质量m=60kg的人站在同滑轮组连接的吊架上,不计滑轮与吊架重力,机械效率为80%.这人利用自 2020-04-25 …
周三社团手工组折红花40朵,(),折黄花几朵?(根据算式补充条件)周三社团手工组折红花40朵,() 2020-04-27 …
一张长方形纸左右对折,上下对折,左右对折,一共对折3次,对折的纸是什么形状?对折出的图形面积是原来 2020-05-16 …
在做疫苗免疫能力实验时设计了两个实验组:一组白鼠接种不含疫苗的东西,另一组接种含疫苗的东西问:为什 2020-05-17 …
兴趣组进行了折纸花活动,第一组3人平均每人折纸花10朵,第二组五人,共折48朵,第3组6人,每人折 2020-06-04 …
在“测定小灯泡的额定功率”的实验中,已知小灯泡的额定电压为2.5V,灯丝电阻约为8欧。小明所在实验 2020-06-18 …
准备一张圆形纸片,在圆内任取不同于圆心的一点F,(接上)将纸片折起,使圆周过点F,然后将纸展开,就 2020-06-30 …
准备一张圆形纸片,在圆内任取不同于圆心的一点F(接上)将纸片折起,使圆周过点F,然后将纸展开,就得 2020-06-30 …
“甘薯所在,居民便有半年之粮,民间渐次广种”这种现象组直接的作用 2020-07-05 …
叶片上面的颜色比下面的深,是因为()A.海绵组织接近上表皮,含叶绿体少B.海绵组织接近下表皮,含叶 2020-07-10 …