婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > Lua編程示例(三):稀疏表、雙端隊列、格式化輸出、表和循環表的格式化輸出

Lua編程示例(三):稀疏表、雙端隊列、格式化輸出、表和循環表的格式化輸出

熱門標簽:外呼系統一天耗費多少流量 昆明電話外呼系統好么 艾比利外呼系統 衡水外呼線路解決 電話機器人每天搜索多少次 免費門店地圖標注注冊入駐 杞縣地圖標注app 陜西便宜電銷機器人軟件 ??谥悄苷Z音電銷機器人好用嗎
a={}
for i=1,10 do
 a[i]={}
 for j=0,10 do
 if(i%2==0) then
  a[i][j]=0
 end
 end
end

print(a[9][10])
print(a[10][10])
print()

--雙端隊列

List={}

function List.new()
 return {first = 0,last = -1}
end

function List.pushleft(list,value)
 local first= list.first-1
 list[first] = value
 list.first= first
end

function List.pushright(list,value)
 local last = list.last+1
 list[last]= value
 list.last=last
end

function List.popleft(list)
 local first=list.first
 if(first>list.last) then
 error("list is empty")
 end
 local res= list[first]
 list[first]=nil
 list.first=list.first+1
 return res
end

function List.popright(list)
 local last = list.last
 if lastfirst then
 error("the list is empty")
 end
 local res = list[last]
 list[last]= nil
 list.last= list.last-1
 return res
end

function List.display(list)
 if(list.first>list.last) then
 error("the list is empty",2)
 end
 for i=list.first ,list.last do
 print(list[i])
 end
end

mylist=List.new()
List.pushleft(mylist,12)
List.pushleft(mylist,"00")
List.pushright(mylist,34)
List.pushright(mylist,56)
List.display(mylist)
print()

function newStack ()
 return {""}
end


function serialize(o)
 if type(o) == "number" then
 io.write(o)
 elseif type(o) == "string" then
  --不要手動加入引號,否則會有邊際效應
 io.write(string.format("%q",o))
 elseif type(o) == "table" then
 io.write("{\n")
 for i,v in pairs(o) do
  io.write("  "..i.." = ")
  serialize(v)
  io.write(",\n")
 end
 io.write("}\n")
 end
end

serialize(123)
print()
serialize("112233")
print()
tab = { a=11,haha="www" ,c=333}
serialize(tab)

function basicSerialize (o)
 if type(o) == "number" then
  return tostring(o)
 else
  return string.format("%q", o)
 end
end

function save (name, value, saved)
 saved = saved or {}  -- 參數未傳入的初始化
 io.write(name, " = ")
 if type(value) == "number" or type(value) == "string" then
 io.write(basicSerialize(value), "\n")
 elseif type(value) == "table" then
 if saved[value] then
  io.write(saved[value], "\tcircle\n")
 else
  saved[value] = name
  io.write("{}\n")
  for k,v in pairs(value) do
   local fieldname = string.format("%s[%s]", name,
    basicSerialize(k))
   save(fieldname, v, saved)
  end
 end
 else
 error("cannot save a " .. type(value))
 end
end

a = {x=1, y=2; {3,4,5}}
a[2] = a  -- 循環表
a.z = a[1]  -- 共享子表

save('a',a)

運行結果:

nil
0

00
12
34
56

123
"112233"
{
  a = 11,
  c = 333,
  haha = "www",
}
a = {}
a[1] = {}
a[1][1] = 3
a[1][2] = 4
a[1][3] = 5
a[2] = a circle
a["y"] = 2
a["x"] = 1
a["z"] = a[1] circle

您可能感興趣的文章:
  • Lua編程中使用嵌套循環的使用教程
  • Lua中的repeat...until循環語句使用教程
  • 詳解Lua中repeat...until循環語句的使用方法
  • Lua中for循環語句的使用教程
  • 詳解Lua中的while循環語句的使用
  • Lua中數字for循環實例
  • Lua中變相實現continue跳出循環
  • Lua中的for循環和迭代器的秘密探究
  • Lua中三種循環語句的使用講解

標簽:西寧 昌都 南京 泰安 營口 臨滄 宿遷

巨人網絡通訊聲明:本文標題《Lua編程示例(三):稀疏表、雙端隊列、格式化輸出、表和循環表的格式化輸出》,本文關鍵詞  Lua,編程,示例,三,稀疏,表,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Lua編程示例(三):稀疏表、雙端隊列、格式化輸出、表和循環表的格式化輸出》相關的同類信息!
  • 本頁收集關于Lua編程示例(三):稀疏表、雙端隊列、格式化輸出、表和循環表的格式化輸出的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 潮安县| 洞头县| 敦化市| 长寿区| 毕节市| 吉水县| 湄潭县| 扎囊县| 仙桃市| 左权县| 沁水县| 岢岚县| 师宗县| 永善县| 陇西县| 安徽省| 尉氏县| 镶黄旗| 鄱阳县| 新营市| 阿拉尔市| 凯里市| 合肥市| 象州县| 炉霍县| 朝阳区| 南江县| 方山县| 城固县| 汉沽区| 乌拉特前旗| 德格县| 镇安县| 女性| 葵青区| 宕昌县| 商城县| 车致| 丹江口市| 石家庄市| 于都县|