I Need Help With a Heap Problem

How do I perform step # 2?


1 Like

Well, you know from the introductory material that a heap is a list of elements. In the class __init__ () method, you created that list, self.heap_list = [None] You also initialized the element count, with self.count = 0.

Now it is time to update those attributes:

  1. Inside of .add() , increment the internal element count, then add the element to the end of the internal list.

One way to increment a number is with number += 1
One way to add an item to the end of a list is with lst.append(item)

1 Like