Answers for "add element to heap python"

1

add element to heap python

import heapq
H = [21,1,45,78,3,5]
# Covert to a heap
heapq.heapify(H)
print(H)
# Add element
heapq.heappush(H,8)
print(H)
Posted by: Guest on June-29-2021

Python Answers by Framework

Browse Popular Code Answers by Language