### n個數的排序--堆排序

n個數的排序
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic Discuss
Problem Description

LeiQ當上了體育委員，現在老師讓他去給班級里的人排隊，LeiQ剛學了排序，所以他想以這種方式給班級里的人排隊（從矮到高），他想知道排序完成后的結果。
Input

Output

Example Input

3
176 175 174
Example Output

174 175 176
Hint

``#include <stdio.h>#include <stdlib.h>#include <iostream>#include <limits.h>#include <algorithm>#define SIZE 10000typedef struct {    int *arr;    int len;}Heap;void heapInit(Heap &H){    H.arr = (int *)malloc(sizeof(int)*SIZE);    H.len = 0;    H.arr[0] = INT_MAX;}void heapAdjust(Heap &H,int start,int end){    int temp = H.arr[start];    for(int i = start*2;i<=end;i=i*2)    {        if(i<end&&H.arr[i+1]>H.arr[i])        {            i++;        }        if(temp>H.arr[i])        {            break;        }        H.arr[start] = H.arr[i];        start = i;     }    H.arr[start] = temp;}void heapInsert(Heap &H,int data){    H.arr[++H.len] = data;    int k = H.len;    while(data>H.arr[k/2])    {        H.arr[k] = H.arr[k/2];        k = k/2;    }    H.arr[k] = data;}void Swap(int *a,int *b){    int temp = *a;    *a = *b;    *b = temp;}void heapSort(Heap &H){    for(int i = H.len;i>0;i--)    {        Swap(&H.arr[1],&H.arr[i]);        heapAdjust(H,1,i-1);    }}int main(){    int n;    while(~scanf("%d",&n))    {        Heap H;        heapInit(H);        for(int i = 0;i<n;i++)        {            int temp ;            scanf("%d",&temp);            //H.arr[++H.len] = temp;            heapInsert(H,temp);        }        heapSort(H);        for(int i = 1;i<=H.len;i++)        {            if(i==1)            {                printf("%d",H.arr[i]);            }            else            {                printf(" %d",H.arr[i]);            }         }          printf("\n");    }    return 0;} ``