用栈实现队列的push、top和pop

来源:互联网 发布:记事本数据导入excel 编辑:程序博客网 时间:2024/06/07 02:33

Python中的list 已经自带append、pop、reverse、remove等方法

class Solution(object):  def push(self,li,data):    li.append(data)    return li  def top(self,li):    if len(li) == 0:      return 'Empty Queue'    return li[0]  def pop(self,li):    if len(li) == 0:      return 'Empty Queue'    return li.pop(0)  def show(self,li):    return liQueue = Solution()li = []print(Queue.push(li,5))print(Queue.push(li,4))print(Queue.push(li,3))print(Queue.push(li,2))print(Queue.push(li,1))print(Queue.top(li))    print(Queue.pop(li))    print(Queue.show(li))


阅读全文
0 0
原创粉丝点击