糖果实验室杂货铺

Candy Lab

MoonScript实现选择排序

6 months ago 0

作者:糖果

LUA代码:

None
1
2
3
4
5
6
7
8
9
10
11
12
13
14
list = {1,5,3,2,9,3,6}
len=#list

for i=1,len 
  max = list[i]
  for j=i+1, len do  
    if list[j]>max then 
      tmp=list[j] 
      list[j]=max
      list[i]=tmp
      max=tmp

for item in *list
  print(item)

MoonScript代码

None
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
local list = { 
  1,  
  5,  
  3,  
  2,  
  9,  
  3,  
  6
}
local len = #list
for i = 1, len do
  local max = list[i]
  for j = i + 1, len do
    if list[j] > max then
      local tmp = list[j]
      list[j] = max 
      list[i] = tmp 
      max = tmp 
    end 
  end 
end
for _index_0 = 1, #list do
  local item = list[_index_0]
  print(item)
end

糖果实验室

Openresty中文编程网
IKBC经典机械键盘
机械键盘领券优惠购买

Write a Comment