Python3 队列实现:FIFO 数据结构详解
Python3 中可以使用 'queue' 模块来定义队列(FIFO)。
示例代码:
import queue
# 定义一个队列
q = queue.Queue()
# 向队列中添加元素
q.put(1)
q.put(2)
q.put(3)
# 从队列中获取元素
print(q.get()) # 输出:1
print(q.get()) # 输出:2
print(q.get()) # 输出:3
注: 'queue' 模块还包括其他类型的队列,如优先队列 PriorityQueue、LIFO 队列 LifoQueue 等。
原文地址: https://www.cveoy.top/t/topic/mXEE 著作权归作者所有。请勿转载和采集!