Python-顺序队列的部分功能的实现

class SqQueue():
    def __init__(self, maxSize):
        self.maxSize = maxSize
        self.queueSlem = [None] * self.maxSize
        self.front = 0
        self.rear = 0
    def clear(self):
        self.front = 0
        self.rear = 0
    def isEmpty(self):
        return self.rear == self.front

    def offer(self, x):
        if self.rear == self.maxSize:
            raise Exception("已满")
        self.queueSlem[self.rear] = x
        self.rear += 1

    def poll(self):
        if self.isEmpty():
            return None
        p = self.queueSlem[self.front]
        self.front += 1
        return p


l = SqQueue(5)
l.offer(3)
l.offer(5)
print(l.queueSlem)
print(l.poll())
print(l.poll())
[3, 5, None, None, None]
3
5
上一篇:线性表篇:普通队列


下一篇:数据结构栈和队列的应用、递归算法