void swap(ElementType *a ,ElementType *b){
ElementType temp;
temp=*a;
*a=*b;
*b=temp;
}
void percDown(ElementType A[],int p,int N){
int child;
ElementType temp;
for(temp=A[p];2*p+1<N;p=child){
child=2*p+1;
if(child!=N-1&&A[child]<A[child+1]){//找左右最大的孩子
child++;
}
if(**temp<A[child]**){
A[p]=A[child];
}else{
break;
}
}
A[p]=temp;
}
void Head_sort(ElementType A[],int N){
int i;
for(i=N/2-1;i>=0;i--){//最大堆
percDown(A,i,N);
}
for(i=N-1;i>0;i--){
swap(&A[0],&A[i]);
percDown(A,0,i);
}
}
/* 你的代码将被嵌在这里 */
ElementType Median( ElementType A[], int N ){
Head_sort(A,N);
return A[N/2];
}
我真是个憨憨小错误都会坑死…