--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() -- 關(guān)閉文件-- 輸出listlocal l = listwhile l do print(l.value) l = l.nextend-- 以下是按行倒序的方法print("以下是按行倒序輸出文件:/n")local file = io.open("table.lua","r") -->打開本本件list = nil --清空list之前的內(nèi)容for line in file:lines() do list = {next = list,value = line}endfile:close() -- 關(guān)閉文件-- 輸出listlocal l = listwhile l do print(l.value) l = l.nextend
新聞熱點
疑難解答
圖片精選