//ÒÑintΪÀý ×î´ó¶Ñ void make_heap(int a[], int size) { } int heap_push(int a[], int n, int data) { int i ; while ( n >= 1 ) { i = (n-1)/2; if (a[i] > data) break; a[n] = a[i]; n = i; } a[n] = data; return n; }
int heap_pop(int a[], int n) { if (n==0) { return a[n]; } int ret = a[0]; int i = 0; int max = 2*i+1; while ( max <= n) { if ( max + 1 <= n ) { max = a[max] > a[max+1]?max:max+1; } if (a[max] <= a[n]) break; a[i] = a[max]; i = max; max = 2*i+1; } a[i] = a[n]; return ret; }