Python heappushpop vs heapreplace
heappushpop(heap, ele) :- This function combines the functioning of both push and pop operations in one statement. Heap order is maintained after this operation.
heapreplace(heap, ele) :- This function also inserts and pops element in one statement, but element is first popped, then the element is pushed.i.e, the value larger than the pushed value can be returned. heapreplace() returns the smallest value originally in heap regardless of the pushed element as opposed to heappushpop(). You can think of heapreplace as headpoppush just for remembering it.
Comments
Post a Comment