;------------------------------------------
;------------------------------------------
#include <Array.au3>
Const $n = 10
Dim $a[$n]
$a[0] = Random(1,10,1)
Dim $i = 1
Dim $m
Dim $ChongFu
While $i < $n
$a[$i] = Random(1,10,1)
$ChongFu = False
For $m = 0 To $i - 1
If $a[$i]= $a[$m] Then
$ChongFu = True
ExitLoop
EndIf
Next
If $ChongFu = False Then ;.
$i = $i + 1
EndIf
WEnd
_ArrayDisplay($a,"10个不重复随机数:")
;---------------------------------------------
;从小到达排序(交换法)
;---------------------------------------------
$i = 0
Dim $j = 0
Dim $temp
For $i = 0 To $n - 2 ;每位数
For $j = $i + 1 To $n - 1 ;每位数与后面的数进行比较
If $a[$j] < $a[$i] Then
$temp = $a[$j]
$a[$j] = $a[$i]
$a[$i] = $temp ;将最小的值放在前面
EndIf
Next
Next
_ArrayDisplay($a,"小->大排序后结果:")
|