?
For construction of a binary heap with property that parent node has value less than child node. In reference to that which line is incorrect. Line indexed from 1.
For construction of a binary heap with property that parent node has value less than child node. In reference to that which line is incorrect. Line indexed from 1.
1. add(int k)
2. {
3. heap_size++;
4. int i = heap_size - 1;
5. harr[i] = k;
6. while (i != 0 && harr[parent(i)] < harr[i])
7. {
8. swap(&harr[i], &harr[parent(i)]);
9. i = parent(i);
10. }
11. }
1. add(int k)
2. {
3. heap_size++;
4. int i = heap_size - 1;
5. harr[i] = k;
6. while (i != 0 && harr[parent(i)] < harr[i])
7. {
8. swap(&harr[i], &harr[parent(i)]);
9. i = parent(i);
10. }
11. }
Join the Discussion
Login to post a comment or share your explanation.
Login