冒泡排序(lua实现)
2015-10-19 15:08
537 查看
function bubble_sort(arr) -- body local tmp = 0 for i=1,#arr-1 do for j=1,#arr-i do if arr[j] > arr[j+1] then tmp = arr[j] arr[j] = arr[j+1] arr[j+1] = tmp end end end end function main( ... ) -- body local arr = {1,20,-1,30,23,21,-108,55,26,55,-2} bubble_sort(arr) for i,v in ipairs(arr) do print(i,v) end end main()
相关文章推荐
- torch中narrow的用法
- LUA中的and与or
- torch7安装方法
- lua学习(一)
- luarocks模块管理工具
- lua优化
- weka:SimpleKMeans实现Class to clusters evaluation验证
- Lua实现类与继承的两种方式(复制)and (闭包)
- VS2012实现C++与Lua交互
- lua的栈
- quick 2.23 它们的定义c++代码lua与总结的一些细节
- lua string库函数详解、实例及lua正则表达式
- LeetCode -- Evaluate Reverse Polish Notation
- LeetCode OJ:Evaluate Reverse Polish Notation(逆波兰表示法的计算器)
- leetcode笔记:Evaluate Reverse Polish Notation(逆波兰式的计算)
- Lua ---- LFS库的使用
- LuaManager实现
- LuaComponent脚本实现
- c++ 与 lua的关系
- casperjs中evaluate() thenEvaluate()的讲解及使用方法