队列
- 实现
class Queue():
def __init__(sef,size):
self.size = size
self.queue = []
self.front= -1
self.rear= -1
def enqueue(self,x):
if self.isFull():
raise exception("queueis full")
else:
self.queue.append(x)
self.rear= self.rear+ 1
def dequeue(self):
if self.isEmpty():
raise exception("queueis empty")
else:
self.queue.pop(0)
self.front= self.front+1
def isFull(self):
return self.rear - self.front == self.size
def isEmpty(self):
return self.rear == self.front
def printStack(self):
print(self.stack)