Understanding understanding Understand Long live!!!
#include <cstdio> #include <cstring> #include <cstdlib> #define MAXSIZE 10typedef struct {int r[maxsize +1];int length;} Sqlist;void Swap (sqlist *l,int i,int j) {int temp = l->r[i]; L->r[i] = l->r[j]; L->R[J] = temp;} void Assignment (SqList *l,int len,int *a) {int i; L->length = Len;for (i=1;i<=len;i++) {l->r[i] = a[i-1];} return;} void Output (SqList L) {int i;for (i=1;i<=l.length;i++) {printf ("%d", L.r[i]);} printf ("\ n"); return;} Try to run your own code//See the "Big Talk Data Structure" 399 pages, must run all the way to understand the general meaning, void Heapadjust (SqList *l,int s,int m) {//Make L from S to M constitute Dagen int temp,j; temp = l->r[s];for (j=2*s;j<=m;j*=2) {//filter down on keywords with larger child nodes if (j<m && l->r[j]<l->r[j+1]) ++j;// J is the subscript if (Temp>=l->r[j]) break for the larger record in the keyword; L->r[s] = L->r[j];s = j;} L->r[s] = Temp;return;} void Heapsort (SqList *l) {int i;for (i=l->length/2;i>0;i--) {heapadjust (l,i,l->length);} for (i=l->length;i>1;i--) {Swap (l,1,i); Heapadjust (l,1,i-1);} return;} int main () {int a[10] = {9,1,5,8,3,7,4,6,2,10}; SqList L; Assignment (&l,10,a); Heapsort (&l); Output (L); return 0;}
Sort-heap Sort