- FIFO(First-In, First-Out)
import queue
q = queue.Queue()
q.put(1)
q.put("Sky")
q.put(True)
# size: 3
print(q.qsize())
# 1, Sky, True
for i in range(q.qsize()):
print(q.get())
- LIFO(Last-In, First-Out)
import queue
lifo_q = queue.LifoQueue()
lifo_q.put("1")
lifo_q.put("Air")
lifo_q.put("True")
# size: 3
print(lifo_q.qsize())
# True, Air, 1
for i in range(lifo_q.qsize()):
print(lifo_q.get())
- PriorityQueue()
import queue
prior_q = queue.PriorityQueue()
prior_q.put((30, 1))
prior_q.put((20, "Sky"))
prior_q.put((10, True))
# size; 3
print(prior_q.qsize())
"""
(10, True)
(20, 'Sky')
(30, 1)
"""
for i in range(prior_q.qsize()):
print(prior_q.get())
'> 자료구조 구현 > 큐' 카테고리의 다른 글
enqueue, dequeue 직접 구현하기 (0) | 2020.09.15 |
---|
댓글