找回密码
 加入
搜索
楼主: zhurongfei

[系统综合] 如何求一维数组里的最小值,帮助文件里说的求不出来【已解决】

 火.. [复制链接]
发表于 2011-4-12 00:15:01 | 显示全部楼层
贴代码要用代码标签,别图省事
#include <Array.au3>

Dim $avArray[2], $i = 0, $Chdir = "D:\DOWNLOAD\2011"
$search = FileFindFirstFile($Chdir & "*.*")
If $search = -1 Then Exit (MsgBox(0, "Error", "No files/directories matched the search pattern"))
While 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
        $i += 1
        ReDim $avArray[$i]
        $avArray[$i - 1] = $file
WEnd
FileClose($search)
MsgBox(4096, "index:", _ArrayMin($avArray, 1))
 楼主| 发表于 2011-4-12 07:47:00 | 显示全部楼层
回复 15# 3mile


    还是未能解决,奇怪了!
 楼主| 发表于 2011-4-12 08:46:06 | 显示全部楼层
回复 16# afan


    谢谢你了,我下次一定会用代码标签的,你帮我解决了困惑好久的问题。关键是ReDim $avArray[$i]这句简直太神奇了,没有看出来它这么大作用!
发表于 2011-4-12 09:50:59 | 显示全部楼层
学习学习再学习,谢谢
发表于 2011-4-13 14:39:49 | 显示全部楼层
本帖最后由 netegg 于 2011-4-13 14:55 编辑

你那堆文件的文件名是什么模样的
另外_arraysort()不行吗
发表于 2011-4-13 19:39:42 | 显示全部楼层
本帖最后由 foboy 于 2011-4-13 19:51 编辑

献上俺写的一个函数:
;排序一个数组。
;参数:$_the_array:原数组;$_mode:0-从大到小/1-从小到大;$_mode_ex:0-返回的数组内容为排序后的数值 1-返回的数组为原数组排序后的序列(角标),例如原数组是[2,6,3],按由大到小排列是[6,3,2],在此模式下函数返回的是其顺序号:[1,2,0]
Func _paixu($_the_array, $_mode = 0, $_mode_ex = 0)
        $_date_num = UBound($_the_array)
        Local $_xulies[$_date_num]
        For $_j = 0 To $_date_num - 1
                $_xulies[$_j] = $_j
        Next
        For $_i_index = 0 To $_date_num - 2
                For $_i = 0 To $_date_num - $_i_index - 2
                        If $_mode == 0 Then
                                If $_the_array[$_i] <= $_the_array[$_i + 1] Then
                                        $_num_linshi = $_xulies[$_i]
                                        $_xulies[$_i] = $_xulies[$_i + 1]
                                        $_xulies[$_i + 1] = $_num_linshi

                                        $_num_linshi = $_the_array[$_i]
                                        $_the_array[$_i] = $_the_array[$_i + 1]
                                        $_the_array[$_i + 1] = $_num_linshi
                                EndIf
                        Else
                                If $_the_array[$_i] >= $_the_array[$_i + 1] Then
                                        $_num_linshi = $_xulies[$_i]
                                        $_xulies[$_i] = $_xulies[$_i + 1]
                                        $_xulies[$_i + 1] = $_num_linshi
                                        $_num_linshi = $_the_array[$_i]
                                        $_the_array[$_i] = $_the_array[$_i + 1]
                                        $_the_array[$_i + 1] = $_num_linshi
                                EndIf
                        EndIf
                Next
        Next
        If $_mode_ex == 1 Then
                Return $_xulies
        Else
                Return $_the_array
        EndIf
EndFunc   ;==>_paixu
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-2 08:39 , Processed in 0.067655 second(s), 13 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表