//HeapSort 堆排序 void Sift(int A[],int low,int high) { int i=low,j=2*i; int temp=A[i]; while(j<=high) { if(j<high && A[j]<A[j+1]) j++; if(temp<A[j]) { A[i]=A[j]; i=j; j=2*i; } else break; } A[i]=temp; } void HeapSort(int A[], int n) { int i,temp; for(i=n/2;i>0;i--) Sift(A,i,n); for(i=n;i>1;i--) { temp=A[1]; A[1]=A[i]; A[i]=temp; Sift(A,1,i-1); } }