题解 | #【模板】循环队列#
【模板】循环队列
https://www.nowcoder.com/practice/0a3a216e50004d8bb5da43ad38bcfcbf
class Circularqueue: def __init__(self, l: int) -> None: self.items = [] self.l = l def push(self, x: int): if len(self.items) >= self.l: return "full" else: self.items.append(x) def front(self): return self.items[0] if self.items else "empty" def pop(self): return self.items.pop(0) if self.items else "empty" n, q = [int(i) for i in input().split()] res = Circularqueue(n) for count in range(q): action = input() if action[:4] == "push": if res.push(int(action.split()[1])): print(res.push(int(action.split()[1]))) elif action == "front": print(res.front()) else: print(res.pop())