lua练习题

1.冒泡排序

function my_sort(a)

    for i=1,#a do
        for j=1,#a-i do  
            if a[j] > a[j+1] then
                a[j],a[j+1] = a[j+1],a[j]
            end 
        end 
    end 

    return a

end

--print(my_sort({1,3,2,5,4}))

tab = my_sort({1,3,2,5,4})

for i,v in ipairs(tab) do
    --print(i,v)
    io.write(v, ' ')
end

io.write("\n")
--io.flush()

https://blog.csdn.net/XIANG__jiangsu/article/details/78262439

https://blog.csdn.net/earbao/article/details/51767543

https://blog.csdn.net/ywjun0919/article/details/50603148

https://www.cnblogs.com/carekee/articles/1745202.html

https://blog.csdn.net/hundaxxx/article/details/48970399

猜你喜欢

转载自blog.csdn.net/Ftworld21/article/details/113859570
今日推荐