#define_CRT_SECURE_NO_WARNINGS1#include<iostream>usingnamespace std;//circulation heapifyvoidheapify(int*a,int f,int b){int l = f *2+1;int r = l +1;while(l<=b){int max;if(r > b)
max = l;else
max = a[l]> a[r]? l : r;if(a[max]> a[f]){
a[max]= a[max]+ a[f];
a[f]= a[max]- a[f];
a[max]= a[max]- a[f];}elsereturn;
f = max;
l = f *2+1;
r = l +1;}}voidheap_sort(int* a,int b){if(b <1)return;//init_heapfor(int i =(b -1)/2; i >=0; i--)heapify(a,i,b);for(int i=b;i>0;i--){
a[0]= a[0]+ a[i];
a[i]= a[0]- a[i];
a[0]= a[0]- a[i];heapify(a,0, i-1);}}intmain(){int a[]={44,3,38,5,47,15,36,26,27,2,46,4,19,50,48};heap_sort(a,sizeof(a)/sizeof(a[0])-1);for(constauto& e : a)
cout << e <<" ";
cout << endl;return0;}/*
//recursion heapify2
void heapify2(int *a,int d,int b) {
int f = d;
int l = f * 2 + 1;
int r = l + 1;
if (l > b)
return;
int max;
if (r > b)
max = l;
else
max = a[l] > a[r] ? l : r;
if (a[max] > a[f]) {
int t = a[f];
a[f] = a[max];
a[max] = t;
}
else
return;
heapify2(a, max, b);
}
*/