TIL | 알고리즘 | 자료구조 | 우선순위 큐

이도운·2022년 1월 15일
0

TIL

목록 보기
51/73
post-thumbnail

우선순위 큐

# min-heap

import heapq

pq = []

heapq.heappush(pq, 456)
heapq.heappush(pq, 123)
heapq.heappush(pq, 789)

print("size : ", len(pq))

while len(pq) > 0:
   print(heapq.heappop(pq))
# min-heap

from queue import PriorityQueue

pq = PriorityQueue()
pq.put(6)
pq.put(10)
pq.put(-5)
pq.put(0)
pq.put(8)

while not pq.empty():
   print(pq.get())
profile
⌨️ 백엔드개발자 (컴퓨터공학과 졸업)

0개의 댓글