arrX:=[8,3,5,7,1,2,3,4,9,6,10,0,12,13,14]
exchangeSort(arrX)
MsgBox % "排序后:`t" printArr(arrX)"`n"
. "最大值:`t"getMax(arrX) "`n"
. "最小值:`t"getMin(arrX) "`n"
return
getMax(arr)
{
max:=arr[1]
for key,val in arr
{
max:= max<=val ? val:max
}
return max
}
getMin(arr)
{
min:=arr[1]
for key,val in arr
{
min:= min>=val ? val:min
}
return min
}
exchangeSort(arr)
{
n:=arr.MaxIndex()
for i,v in arr
{
loop % n-i
{
j:=i+A_Index
if (arr[j]<arr[i])
{
temp :=arr[j]
arr[j] := arr[i]
arr[i] := temp
}
}
}
}
printArr(arr)
{
s:="["
for k,v in arr
{
s.=v . ","
}
s.="]"
return s
}
[FUNC]exchangeSort
最新推荐文章于 2021-08-11 22:15:03 发布