六大经典算法

2022-10-13 03:19:22   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《六大经典算法》,欢迎阅读!
算法,六大,经典
枚举算法

1-2009年之间闰年数



为统计1-2004自然数之中3的倍数的个数,有人设计了左边的算法流程图,请你仔细阅读后把它填写完整.



一份单据中被涂抹的数字的推算。一张单据上有一个5位数的编号,其百位数和十

位数处已经变得模糊不清,但是知道这5位数是3767的倍数。现在要设计一个

算法,找出所有满足这些条件的5位数,并统计这些5位数的个数。






冒泡排序



冒泡排序核心程序

数组d存放待排序数据,d(1)~d(n),按非减次数排列

For i=1 to n-1

For j=n to i+1 step -1 If d(j)

temp=d(j):d(j)=d(j-1):d(j-1)=temp


End If Next j Next i

冒泡排序代码设计

Dim d(1 To 128) As Integer

Dim ct As Integer '定义全局变量 Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then ct = ct + 1

d(ct) = Val(Text1.Text) List1.AddItem Str(d(ct))

Text1.Text = "": Text1.SetFocus '准备在text1接受下一个数据 End If End Sub



选择排序




选择排序核心程序

数组d存放待排序数据,d(1)~d(n),按非减次数排列

For i = 1 To n - 1 k = i

For j = i + 1 To n

If d(j) < d(k) Then k = j Next j

If i <> k Then

temp = d(i): d(i) = d(k): d(k) = temp End If Next i 选择排序代码设计

Dim a(1 To 6) As Integer

Dim n As Integer, i As Integer

Dim j As Integer, k As Integer '定义全局变量 Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then n = n + 1

a(n) = Val(Text1.Text) List1.AddItem Str(a(n)) Text1.Text = "" Text1.SetFocus End If End Sub

Private Sub Command1_Click() For i = 1 To n - 1 k = i

For j = i + 1 To n If 此处自己填写 Then k = j Next j

If i <> k Then t = a(i)


a(i) = a(k)

此处自己填写 End If Next i

For i = 1 To n

List2.AddItem Str(a(i)) Next i End Sub

顺序查找



对分查找




本文来源:https://www.wddqxz.cn/1c854e4d986648d7c1c708a1284ac850ad02042f.html

相关推荐