heapq 모듈은 이진 트리(binary tree) 기반의 최소 힙(min heap)자료구조를 제공한다.

 

사용법

import heapq

# 자료형은 특수한 자료형이 아닌 리스트이다.
heap = []
# 값 넣는 방법
heapq. heappush(heap, 4)
# 값 빼는 법
print(heapq.heappop(heap))
# 값 삭제하지 않고 얻기
print(heap[0])
# 기존 리스트를 힙으로 변환
heapq.heapify(heap)

'알고리즘' 카테고리의 다른 글

자바 배열 정렬  (0) 2021.10.29
[java -heap]PriorityQueue 최소값 반환  (0) 2021.10.28
더 맵게[python3]  (0) 2021.10.27
[알고리즘] 버블 정렬(Bubble Sort)  (0) 2020.06.28
[알고리즘] 선택 정렬(Selection Sort)  (0) 2020.06.28

+ Recent posts