Question: heap ( A [ 1 - - n ] , i ) if 2 i n check if the left child exist heap ( A

heap (A[1--n], i)
if 2in check if the left child exist
heap (A,2i)
heap (A,2i+1)
if A[2i]>A[i]&A[2i]>A[2i+1]
we should check if there is a right child by using nested if.
swap A[2i]& & heap (A,2i); else if A[2i+1]>A[i]&A[2i+1]>A[2i] swap 2i+1 & A[i] A heap (A,2i+1);
for i=1, to n
swap A[1] & A[n-i+1]
j=1
while 2j(n-i)
if A[2j]>A[j]&,A[2j]>A[2j+1]
swap A[2j]&A[j];,jlarr2j;
else if A[2j+1]>A[2j]
swap A[2j+1]&A[j];j=j+1;
This is a pseudo code for the heap algorithm i need to compute it as a simple C code ( a working code ) i need the explanation of the code line by line . Please use simple C functions
heap ( A [ 1 - - n ] , i ) if 2 i n check if the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!