--table 特性-- 使用table生成正序和倒序的链表-- 使用table生成链表list = nillocal file = io.open("table.lua","r") -->打开本本件pre = nil--将本文件按行顺序读入list中for line in file:lines() do current = {next = nil,value = line} pre = pre or current list = list or pre pre.next = current pre = currentendfile:close() -- 关闭文件-- 输出listlocal l = listwhile l do print(l.value) l = l.nextend-- 以下是按行倒序的方法print("以下是按行倒序输出文件:/n")local file = io.open("table.lua","r") -->打开本本件list = nil --清空list之前的内容for line in file:lines() do list = {next = list,value = line}endfile:close() -- 关闭文件-- 输出listlocal l = listwhile l do print(l.value) l = l.nextend
新闻热点
疑难解答