You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
557 B
Python
27 lines
557 B
Python
7 months ago
|
class Queue(object):
|
||
|
"""实现一个队列"""
|
||
|
|
||
|
def __init__(self, length = 20):
|
||
|
self.list = []
|
||
|
self.__length = length
|
||
|
|
||
|
def enqueue(self, elem):
|
||
|
"""入队"""
|
||
|
if self.size() > self.__length:
|
||
|
self.dequeue()
|
||
|
self.list.append(elem)
|
||
|
else:
|
||
|
self.list.append(elem)
|
||
|
|
||
|
def dequeue(self):
|
||
|
"""出队"""
|
||
|
return self.list.pop(0)
|
||
|
|
||
|
def is_empty(self):
|
||
|
return not self.list
|
||
|
|
||
|
def size(self):
|
||
|
"""队列的大小"""
|
||
|
return len(self.list)
|
||
|
|