Queue = {} function Queue.newquene() return {count = 0} end function Queue.push(queue, value) queue.count = queue.count+1 queue[queue.count] = value end function Queue.pop(queue) queue[queue.count] = nil queue.count = queue.count-1 end --按入队顺序输出 function Queue.print( queue ) local i=1 while queue[i] do print(queue[i]) i = i+1 end end --按出对顺序输出 function Queue.printReverse( queue ) local i=queue.count while queue[i] do print(queue[i]) i = i-1 end end local que = Queue.newquene() for i=1, 9 do Queue.push(que, i) end Queue.print(que) Queue.pop(que) Queue.printReverse(que)
时间: 2024-10-08 14:37:02