본문 바로가기
> 자료구조 구현/힙

최소 힙(min heap)의 구조를 가지고 있는 우선순위 큐 구현

by bky373 2020. 10. 10.
import heapq

queue = []

heapq.heappush(queue, [2, 'A'])
heapq.heappush(queue, [5, 'B'])
heapq.heappush(queue, [1, 'C'])
heapq.heappush(queue, [7, 'D'])

print(queue)
""" [[1, 'C'], [5, 'B'], [2, 'A'], [7, 'D']] """

for x in range(len(queue)):
    print(heapq.heappop(queue))

"""
    [1, 'C']
    [2, 'A']
    [5, 'B']
    [7, 'D']
"""


- 출처 : FASTCAMPUS

'> 자료구조 구현 > ' 카테고리의 다른 글

힙(heap)의 기본 구현  (0) 2020.10.10
힙(heap)의 기본  (0) 2020.10.10

댓글