排序的问题!!!!各位请进来瞧瞧!
我现在有个数组array(1 to 40)
每个的值的范围从1-6
现在想找出该数组里面最大的六个,请问该如何做?麻烦各位给瞧瞧,非常感谢,一定送分哟!!!!
问题点数:50、回复次数:14Top
1 楼Fanks(铁面人)回复于 2002-04-30 17:44:24 得分 2
用一个变量循环比较数组的每个成员,取得最大值,地二次同样,但条件是小于第一次取得的最大值,第三次又要小于第二次,依次类推。Top
2 楼jamsband(东子)回复于 2002-04-30 17:45:34 得分 0
能否给俺写写呀Top
3 楼neverwin(老青蛙)回复于 2002-04-30 17:46:48 得分 2
排序
取头6个
Top
4 楼neverwin(老青蛙)回复于 2002-04-30 17:55:28 得分 5
Global Const ZERO = 0
Global Const ASCENDING_ORDER = 0
Global Const DESCENDING_ORDER = 1
Global gIterations
Sub BubbleSort(MyArray(), ByVal nOrder As Integer)
Dim Index
Dim TEMP
Dim NextElement
NextElement = ZERO
Do While (NextElement < UBound(MyArray))
Index = UBound(MyArray)
Do While (Index > NextElement)
If nOrder = ASCENDING_ORDER Then
If MyArray(Index) < MyArray(Index - 1) Then
TEMP = MyArray(Index)
MyArray(Index) = MyArray(Index - 1)
MyArray(Index - 1) = TEMP
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
End If
End If
Index = Index - 1
gIterations = gIterations + 1
Loop
NextElement = NextElement + 1
gIterations = gIterations + 1
Loop
End Sub
Top
5 楼beesoft(男人简单就好)回复于 2002-04-30 22:28:56 得分 1
笨方法,加上listbox等控件(设置sorted属性为true),将数组添入可以看到吧Top
6 楼limengchen(LMC)回复于 2002-04-30 22:50:13 得分 3
dim max(1 to 6) as integer
dim i as integer
dim j as integer
for i=1 to 6
for j=1 to 40
if max(i)<array(j) then0D
max(i)=array(j)
array(j)=0
end if
next j
next i
================================================================
CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!
★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。
★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。
Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar
Http://www.ChinaOK.net/csdn/csdn.exe [自解压]
Top
7 楼jamsband(东子)回复于 2002-05-08 09:40:07 得分 0
我现在有个数组array(1 to 40)
每个的值的范围从1-6
现在想让该数组由大到小排序,然后从大到小找出大于4的数组,如果超过六个则取前六个,如果小于六个,那么有几个取几个,因为最后我是要去匹配,假设有三个
array(1),array(14),array(28)这时候我就会到数据库检索... where job in (1,14,28)
所以我要记录下数组的下标,in后面最多有六个,也就是小于等于6个,我怎么处理好,我想不出好的办法,请各位兄弟帮我写写看,一定送分Top
8 楼jamsband(东子)回复于 2002-05-08 10:53:56 得分 0
怎么没人回答俺呀Top
9 楼nichole()回复于 2002-05-08 11:07:53 得分 1
为什么要大于4呢?看不懂Top
10 楼jamsband(东子)回复于 2002-05-08 11:31:43 得分 0
因为程序要求的呀Top
11 楼Jameszht(湖泊)回复于 2002-05-08 11:52:04 得分 5
dim max(1 to 6) as integer
dim i as integer
dim j as integer
for i=1 to 6
for j=1 to 40
if max(i)<array(j) then0D
max(i)=array(j)
array(j)=0
end if
next j
if max(i)<4 then exit for
next i
strRange=""
for i=1 to 6
if max(i)>=4 then
strRange=strRange & max(i) &","
else
exit for
endif
next
strRange=left(strRange,len(strRange)-1)
"...where job in (" & strRange &")"
Top
12 楼combread()回复于 2002-05-08 13:53:10 得分 10
东子,他们的算法,也是可以的.
其实我采用的是最笨的算法,气泡法.
呵呵......
不过楼上的一些源代码,也是气泡法啊.
^_^Top
13 楼combread()回复于 2002-05-08 13:58:48 得分 20
老大,发给你的程序到底好不好用阿.
你看着,
intProFour()存放大于4的数据
intProFourMark()存放大于4数据在原始数组中的下标
本来也可以用二维数组的,我懒得动了.^_^
两个数组中的元素个数相同并且一一对应
用的时候从中间取出数据就可以了.Top
14 楼funny001(巴山夜雨)回复于 2002-05-08 14:08:44 得分 1
插入排序,选择排序,交换排序,快速排序,起泡排序。老兄看看数据结构吧Top




