lua中Table数据结构
来源:互联网 发布:农村淘宝投诉电话多少 编辑:程序博客网 时间:2024/04/27 15:02
一,table数据结构可以看成其实高级语言中的数组
二,操作table的一引起函数
(1)table.getn(myTable)返回table中的元素个数
(2)对table中的数据排序
从小到大排序:
local function main()myTable = {2,5,2,8,4,4,6};table.sort(myTable);for index = 1,table.getn(myTable) do print(myTable[index]); endend --执行函数main()也可以用一个函数来决定是降序或升降
local function main()sourceTable = {7,5,63,4,52,4,33,2}; function Sort(myTable,direction) if direction == 1 then --从小到大排序 table.sort(myTable); else function Reverse(a,b) if a <= b then return false; else return true; end end table.sort(myTable,Reverse); end end Sort(sourceTable,10); for index = 1,table.getn(sourceTable) do print(sourceTable[index]); endend --执行函数main()(3)table.insert(myTable,position,value)向table中插入一个值,如果position没有,则添加到末尾。
(4)table.remove(myTable,position);移除一个值
(5)pairs(),可以遍历table中的每一个元素
local function main()mytable = {"fred","aaa","maa","ffff"};for index,value in pairs(mytable) do print(index,value);endend --执行函数main()
0 0
- lua中Table数据结构
- Lua中table介绍
- lua中table活用
- Lua 中Table遍历
- lua中table总结
- lua中 table
- lua基础【三】唯一数据结构table表
- lua中的数据结构-table常用函数库
- Lua数据结构 — Table(三)
- Lua数据结构 — Table(三)
- lua之table数据结构分析(一)
- lua数据结构之table的内部实现
- 【Lua】浅析Lua中table的遍历
- 【Lua】浅析Lua中table的遍历
- lua 中table 内嵌table
- 理解lua中Weak Table
- lua中设置只读table
- Lua中table的copy
- sharepoint 2013 office web app 2013 文档在线浏览 IE11 浏览器不兼容解决方法
- Jasper Server Active Directory Integration
- js调试小技巧之console.log()
- Eclipse-jee中安装tomcatPlugin
- 【leetcode】 Longest Common Prefix
- lua中Table数据结构
- 《COC部落战争》新手速成攻略
- UVa 1401 Remember the Word
- Are you missing a call to unregisterReceiver()? 解决方法
- 命令行提示符里怎么远程连接MongoDB
- UITextView 文本换行
- 分布式搜索引擎elasticsearch PHP API index curd
- mongodb在需要用户名密码授权的情况下导入数据
- Pinyin4j.jar介绍中文转拼音