手写堆栈和队列

  

#后进先出:栈
class stack(object):
    def __init__(self):
        self.data =[]

    def push(self,item):
        self.data.append(item)

    def pop(self):
        return self.data.pop()

#先进先出:队列

class Queue(object):
    def __init__(self):
        self.data=[]

    def push(self,item):
        self.data.insert(0,item)

    def pop(self):
        return self.data.pop()


    

  

猜你喜欢

转载自www.cnblogs.com/mengbin0546/p/9979231.html