队列
FIFO 先进先出
队列的实现
class Queue(object):
def __init__(self):
self.__list = []
def enqueue(self, item):
self.__list.append(item)
def dequeue(self):
return self.__list.pop(0)
def is_empty():
return self.__list == []
def size():
return len(self.__list)
if __name__ == '__main__':
q = Queue()
q.enqueue(1)
双端队列的实现
class Dqueue(object):
def __init__(self):
self.__list = []
def add_front(self, item):
self.__list.insert(0, item)
def add_rear(item):
self.__list.append(item)
def pop_front(self):
return self.__list.pop(0)
def pop_rear(self):
return self.__list.pop()
def is_empty():
return self.__list == []
def size():
return len(self.__list)
if __name__ == '__main__':
d = Dqueue()
标签:__,.__,return,队列,self,list,算法,数据结构,def
From: https://www.cnblogs.com/superhin/p/17464291.html