KKG
Programming
KKG
전체 방문자
오늘
어제
  • 전체 글 보기 (84)
    • 회고 (9)
    • Bootcamp (19)
    • Error Handling (2)
    • Kotlin (1)
    • Java (19)
      • Java (14)
      • Spring (1)
      • JPA (2)
      • Link (2)
    • Python (5)
    • 알고리즘 (20)
      • 알고리즘 (4)
      • 백준 (14)
      • 프로그래머스 (1)
      • Link (1)
    • SQL (5)
      • SQL (1)
      • MySQL (4)
    • Web (2)
    • etc (1)

블로그 메뉴

  • 태그
  • 방명록
  • 깃허브

인기 글

티스토리

hELLO · Designed By 정상우.
KKG

Programming

Python

[Python] 힙 자료구조 Heapqueue

2022. 1. 28. 15:24

가장 작은 값이 항상 앞에 오는 자료구조

 - 최대값, 최솟값을 빠르게 찾아내기 위해 고안되었다

import heapq

heap = []

heapq.heappush(heap, 5) # heap = [ 5 ]
heapq.heappush(heap, 1) # heap = [ 1, 5 ]
heapq.heappush(heap, 2) # heap = [ 1, 5, 2 ]
heapq.heappop(heap)     # heap = [ 2, 5 ]

print(heap)
출력값
[2, 5]

 

heap = [ 5, 1, 2 ]
heapq.heapify(heap) # heap = [ 1, 5, 2 ]

print(heap)
출력값
[1, 5, 2]
    'Python' 카테고리의 다른 글
    • [Python] 중복순열, 중복조합(itertools.product, combinations_with_replacement)
    • [Python] collections.Counter
    • [Python] 순열, 조합(itertools.permutations, combinations)
    • [Python] 누적합 itertools.accumulate

    티스토리툴바