mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
25 lines
400 B
Python
25 lines
400 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
# author: bt3gl
|
|
|
|
|
|
import heapq
|
|
|
|
min_heap = [3,1,2]
|
|
heapq.heapify(min_heap)
|
|
|
|
max_heap = [-x for x in min_heap]
|
|
heapq.heapify(max_heap)
|
|
|
|
heapq.heappush(min_heap, 5)
|
|
heapq.heappush(min_heap, -5)
|
|
|
|
min_elem = min_heap[0]
|
|
max_elem = -1 * max_heap[0
|
|
|
|
heapq.heappop(min_heap)
|
|
heapq.heappop(max_heap)
|
|
|
|
size_min_heap = len(min_heap)
|
|
size_max_heap = len(max_heap)
|