LUA 栈实现

来源:互联网 发布:如何修改考勤机数据 编辑:程序博客网 时间:2024/05/22 05:16
function STACK_EMPTY(S)
if S.top == 0then
return true
end
return false
end

function PUSH(S,x)
S.top = S.top + 1
S[S.top] = x
end

function POP(S)
if STACK_EMPTY(S)thenreturn('underflow')
else
S.top = S.top - 1
local v = S[S.top+1]
S[S.top+1] = nil
return v
end
end

原创粉丝点击