实现Lua的双向队列

--[[
 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


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值