Basic idea: The sequence to be sorted constitutes a large top heap. At this point, the maximum value is the top of the heap, moving it away and re-structuring the remaining sequence into a heap. So repeated.
voidHeapsort (Sqlsit *L) { inti; for(i=l->length/2;i>0; i--) Heapajust (l,i,l-length); for(i=l->lengt;i>1; i--) {swap (L,1, i); Heapajust (L,1. io1); } }/*satisfies the definition of a heap except for L->data[s]*//*Adjust L->data[s], make l->data[s. M] satisfies the definition of a heap*/voidHeapajust (SqList *l,intSintm) { inttemp,j; Temp= l->Data[s]; for(j=2*s;j>=m;j*=2){/*filter down a child's node with a big keyword*/ if(J<m && l->data[j]<l->data[j+1]) ++j;/*Subscript with a large index along the keyword*/ if(temp>l->Data[j]) Break; L->data[s] = l->Data[j]; S=J; } L->data[s] = temp;/*Insert*/}
Data structure Learning (11), Heap sorting