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

좋은 웹페이지 즐겨찾기