| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 424 人关注过本帖
标题:[求助]插入法排序出错
取消只看楼主 加入收藏
djccit
Rank: 1
等 级:新手上路
帖 子:87
专家分:0
注 册:2005-12-26
收藏
 问题点数:0 回复次数:0 
[求助]插入法排序出错

Option Explicit

Private Sub Command1_Click()
Dim a(10) As Integer, s() As Integer, i As Integer
Dim j As Integer, st As String
For i = 1 To 10
a(i) = Int(Rnd * 90) + 10
Text1.Text = Text1 & Str(a(i))
Next i

ReDim s(1)
s(1) = a(1)

List1.AddItem Str(s(1))

For i = 2 To 10
st = ""
Call sort(a(i), s)

For j = i To UBound(s)
st = st & Str(s(j))
Next j

List1.AddItem st
Next i
End Sub
Private Sub sort(n As Integer, s() As Integer)
Dim i As Integer, j As Integer, k As Integer
k = UBound(s)
ReDim Preserve s(k + 1)

For i = 1 To k
If n <= s(i) Then

For j = k To i Step -1
s(j + 1) = s(j)
Next j

s(i) = n: Exit Sub
End If
Next i

s(i) = n

End Sub


2006-03-15 21:03
快速回复:[求助]插入法排序出错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023004 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved