VB资料之家 计算机二级考试一扫空(36)

2026/1/15 6:09:49

9.3 数组应用例题(根据时间可以选择一个讲!) 根据需要,选择1-2道下面的题目,给学生讲清楚算法的思想!

1 排序

例5-3 选择排序法 直接排序法

Option Explicit

Option Base 1

Private Sub CmdSort_Click()

Dim Sort(10) As Integer, Temp As Integer Dim I As Integer, J As Integer Randomize For I = 1 To 10

Sort(I) = Int(Rnd * (100 - 1)) + 1 Text1 = Text1 & Str(Sort(I)) Next I

For I = 1 To 9

For J = I + 1 To 10

If Sort(I) > Sort(J) Then Temp = Sort(I) Sort(I) = Sort(J) Sort(J) = Temp

End If Next J

Text2 = Text2 & Str(Sort(I)) Next I

Text2 = Text2 & Str(Sort(10)) End Sub

Option Explicit Option Base 1

Private Sub CmdSort_Click()

Dim Sort(10) As Integer, Temp As Integer Dim I As Integer, J As Integer Dim Pointer As Integer Randomize For I = 1 To 10

Sort(I) = Int(Rnd * (100 - 1)) + 1 Text1 = Text1 & Str(Sort(I)) Next I

For I = 1 To 9 Pointer = I

For J = I + 1 To 10

If Sort(Pointer) > Sort(J) Then Pointer = J End If Next J

If I <> Pointer Then Temp = Sort(I) Sort(I) = Sort(Pointer) Sort(Pointer) = Temp End If

Text2 = Text2 & Str(Sort(I)) Next I

Text2 = Text2 & Str(Sort(10))

End Sub

2 查找

例:5-4 顺序查找程序 (界面见P105) 先介绍For Each –next 结构的语句: Option Explicit

Option Base 1 Dim Search As Variant


VB资料之家 计算机二级考试一扫空(36).doc 将本文的Word文档下载到电脑
搜索更多关于: VB资料之家 计算机二级考试一扫空(36) 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219