--[[
file name . GameList.lua
author . Clark/陈泽丹
created . 8.13.2011
purpose . 双向队列
--]]
module("GameList", package.seeall)
--双向队列
function list_newList()
local first = 1
local last = 0
local list = {}
local listManager = {}
function listManager.pushFront(_tempObj)
first = first - 1
list[first] = _tempObj
end
function listManager.pushBack(_tempObj)
last = last + 1
list[last] = _tempObj
end
function listManager.temp_getFront()
if listManager.bool_isEmpty() then
return nil
else
local val = list[first]
return val
end
end
function listManager.temp_getBack()
if listManager.bool_isEmpty() then
return nil
else
local val = list[last]
return val
end
end
function listManager.popFront()
list[first] = nil
first = first + 1
end
function listManager.popBack()
list[last] = nil
last = last - 1
end
function listManager.clear()
while false == listManager.bool_isEmpty() do
listManager.popFront()
end
end
function listManager.bool_isEmpty()
if first > last then
first = 1
last = 0
return true
else
return false
end
end
function listManager.d_getSize()
if listManager.bool_isEmpty() then
return 0
else
return last - first + 1
end
end
return listManager
end
本文介绍了一个使用Lua编写的双向队列的数据结构实现方法。该队列支持从前端和后端添加及移除元素,提供了获取队列首尾元素的功能,并实现了清空队列和检查队列是否为空的操作。
1089

被折叠的 条评论
为什么被折叠?



