class Queue: def __init__(self, limit=10): self.data = [None] * limit self.head = -1 self.tail = -1
时间: 2024-05-22 13:14:47 浏览: 128
msmq.rar_MSMQ CSharp_csharp msmq_message queue_msmq_site:www.p
def is_empty(self): return self.head == -1 def is_full(self): return (self.tail + 1) % len(self.data) == self.head def enqueue(self, val): if self.is_full(): raise Exception("Queue is full") if self.head == -1: self.head = 0 self.tail = (self.tail + 1) % len(self.data) self.data[self.tail] = val def dequeue(self): if self.is_empty(): raise Exception("Queue is empty") val = self.data[self.head] if self.head == self.tail: self.head = -1 self.tail = -1 else: self.head = (self.head + 1) % len(self.data) return val
阅读全文