对一组无序数据,①设计直接插入排序算法;②再对得到的有序序列进行折 半查找.
来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/06/28 06:32:41
对一组无序数据,①设计直接插入排序算法;②再对得到的有序序列进行折 半查找.
![对一组无序数据,①设计直接插入排序算法;②再对得到的有序序列进行折 半查找.](/uploads/image/z/19872559-55-9.jpg?t=%E5%AF%B9%E4%B8%80%E7%BB%84%E6%97%A0%E5%BA%8F%E6%95%B0%E6%8D%AE%2C%E2%91%A0%E8%AE%BE%E8%AE%A1%E7%9B%B4%E6%8E%A5%E6%8F%92%E5%85%A5%E6%8E%92%E5%BA%8F%E7%AE%97%E6%B3%95%EF%BC%9B%E2%91%A1%E5%86%8D%E5%AF%B9%E5%BE%97%E5%88%B0%E7%9A%84%E6%9C%89%E5%BA%8F%E5%BA%8F%E5%88%97%E8%BF%9B%E8%A1%8C%E6%8A%98+%E5%8D%8A%E6%9F%A5%E6%89%BE.)
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
再问: 要C++程序
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
再问: 要C++程序
一、实验目的:掌握常用的查找与排序算法.二、实验内容 1、用简单插入排序法,对关键字值序列为:9,2,
用直接插入排序法对:7,1,3,12,8,4,9,10进行从小到大排序时,第四步得到的一组数为:______.
已知序列(35,78,12,26,90,41,66,58),请写出对该序列采用直接插入排序进行升序排序的前四趟结果
对下列关键字序列(15,4,38,51,9,17,80,2)进行直接插入排序?
从键盘读入一串整数构造一棵二叉排序树,并对得到的二叉排序述进行中序遍历,得到有序序列.
对同一个基本有序的待排序列分别进行堆排序、快速排序和冒泡排序,最省时间的算法是___________
假设关键字序列为{9,3,5,1,2,6,4,7,8},用直接选择排序算法对关键字进行排序
对元素序列如何进行堆排序
用SPSS对一组数据进行均值检验,得到一组结果;再把同样的数据复制一次,再对此两组数据重新作检验.
设计一个算法,将某一个X值插入到一个有序(运用顺序存储结构),对线性表进
已知序列(35.78.12.26.90.41.66.58)请写出对该序列采用直接插入排列进行升序排列的前四趟结果
用matlab 对一组数据进行拟合后,怎么直接显示拟合函数的图像?