The following steps are followed for creating a max-heap:
- The user is asked to enter a number. The number is used to create a heap. The number entered by the user is assigned to an array heap at index location x, where x begins with a value of 0 and increments after every insertion.
- The newly inserted number is compared with the element of its parent node. Because we are making use of a max-heap, we need to maintain a rule: the value of the parent node should be always larger than its child node. The location of the parent node is computed using the formula parent=(x-1)/2, where x represents the index location where the new node is inserted.
- Check if the value of the new node is greater than the value of its parent. Interchange ...