标签:排序 ++ 实现 void oid bsp span The nbsp
1 void AdjustHeap(int *a,int n,int cur) 2 { 3 int i,tmp; 4 for(i=2*cur+1;i<n;i=i*2+1) 5 { 6 if(i<n-1 && a[i]<a[i+1]) 7 ++i; 8 if(a[cur]>a[i]) 9 break; 10 tmp = a[cur]; 11 a[cur] = a[i]; 12 a[i] = tmp; 13 cur = i; 14 } 15 } 16 17 void HeapSort(int *a,int n) 18 { 19 int i,j,tmp; 20 for(i=(n-2)/2;i>=0;--i) 21 AdjustHeap(a,n,i); 22 23 for(j=n-1;j>0;--j) 24 { 25 tmp = a[0]; 26 a[0] = a[j]; 27 a[j] = tmp; 28 AdjustHeap(a,j,0); 29 } 30 }
标签:排序 ++ 实现 void oid bsp span The nbsp
原文地址:https://www.cnblogs.com/susidian/p/10013138.html