solidity-examples icon indicating copy to clipboard operation
solidity-examples copied to clipboard

Bug in function pop()

Open lukehutch opened this issue 3 years ago • 0 comments

The left child of node i has index 2 * i + 1, and the left child has index 2 * i + 2. You are using 2 * i and 2 * i + 1 respectively, which (for a full implementation of min-heapify) leads to an infinite loop if you are trying to min-heapify starting at index 0, since 2 * 0 == 0.

https://github.com/chriseth/solidity-examples/blob/master/heap.sol#L54

lukehutch avatar May 18 '22 05:05 lukehutch