标签:col for -- key 调用 print else style clu
#include <stdio.h> typedef int KeyT; typedef int ElemType; typedef struct { KeyT key; ElemType data; }ST; void Sift(ST R[],int low,int high) //i=low.n=high { int i=low,j=2*i; ST t=R[i]; //st与sifyt互相调用 while(j<=high) { if(j<high&&R[j].key<R[j+1].key) j++; if(t.key<R[j].key) { R[i]=R[j]; i=j; j=2*i; } else break; } R[i]=t; } void HS(ST R[],int n) { int i; ST t; for(i=n/2;i>=1;i--) Sift(R,i,n); for(i=n;i>=2;i--) { t=R[1]; R[1]=R[i];R[i]=t; Sift(R,1,i-1); } } int main() { ST R[100]; KeyT A[]={75,87,68,92,88,61,77,96,80,72}; int i,n=10; for(i=0;i<n;i++) R[i+1].key=A[i]; HS(R,n); printf("排序结果:"); for(i=1;i<=n;i++) printf("%3d",R[i].key); printf("\n"); }
标签:col for -- key 调用 print else style clu
原文地址:https://www.cnblogs.com/huangjiaxin/p/11002757.html