Insert (H, k)

The above procedure inserts an element with key value ‘k’ in a given maximum heap. The heap-size in incremented by 1 after the insertion of the element with key ‘k’.

Step 1 Incrementing the array size, assuming size does not exceed the maximum array size.

set heap-size [H] heap-size [H] + 1

Step 2 initialization

set i heap-size [H]

Step 3 loop, obtaining proper position

while (i > 1 and H [Parent (i)] < k

set H [i] H [Parent (i)]

set i Parent (i)

Step 4 Insertion

set H [i] k

Step 5 return at the point of call

return

## 2 comments:

Thanks to the writer of this article. I appreciate your effort in making this informational blogs. I know it's not easy to do this but you have done a really great job. Congrats. I'm pretty sure your readers enjoying it a lots.

Rica

www.imarksweb.org

Thanks for sharing such a wonderful article, I hope you could inspire more people. Visit my site too.

n8fan.net

www.n8fan.net

Post a Comment