
typedef int Datatype;
typedef struct
{Datatype* elem; int Length;
}SqList;
typedef SqList HeapType;
void swap(int* a, int* b)
{int tmp = *a;*a = *b;*b = tmp;
}
void HeapAdjust(HeapType H, int s, int m)
{int child = s * 2;while(child <= m){ if (child + 1 <= m && H.elem[child] < H.elem[child + 1])++child; if (H.elem[s] < H.elem[child]){swap(&H.elem[child], &H.elem[s]);s = child;child = s * 2;}elsebreak;}
}
void HeapSort(HeapType H)
{ for (int i = H.Length / 2; i >= 1; i--){HeapAdjust(H, i, H.Length);}for (int end = H.Length; end >= 2; end--){swap(&H.elem[1], &H.elem[end]);HeapAdjust(H, 1, end - 1);}
}
int main()
{HeapType L;HeapSort(L);for (int i = 1; i <= L.Length; i++){printf("%d ", L.elem[i]);}return 0;
}