#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int check_heap(int a[], int n);
void insert(int val, int a[], int *n);
int main(void) {
int a[11] = {1,13,71,14,15,80,91,24,60,63};
int n;
int i;
int b,c;
b = random() % 100 + 1;
n = 10;
insert(b, a, &n);
printf("%d\n", check_heap
(a
, 11));
for(i = 0; i < 11; i++){
}
return 0;
}
int check_heap(int a[], int n) {
int i;
int m;
m = (n - 1) / 2;
for(i = 0; i < m; i++)
{
if(a[i] >= a[i * 2 + 1])
{
return 0;
}
if(a[i] >= a[i * 2 + 2]){
return 0;
}
}
if(n % 2 == 0){
if(a[(n - 1)/2] > a[n - 1]){
return 0;
}
}
return 1;
}
void insert(int val, int a[], int *n) {
int temp;
a[*n] = val;
while(a[(*n-1) / 2] >= a[*n]){
temp = a[(*n-1) / 2];
a[(*n-1) / 2] = a[*n];
a[*n] = temp;
}
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RkbGliLmg+CiNpbmNsdWRlPHRpbWUuaD4KaW50IGNoZWNrX2hlYXAoaW50IGFbXSwgaW50IG4pOwp2b2lkIGluc2VydChpbnQgdmFsLCBpbnQgYVtdLCBpbnQgKm4pOwoKIAppbnQgbWFpbih2b2lkKSB7CiAgaW50IGFbMTFdID0gezEsMTMsNzEsMTQsMTUsODAsOTEsMjQsNjAsNjN9OwogIGludCBuOwogIGludCBpOwogIGludCBiLGM7CgogIHNyYW5kb20odGltZShOVUxMKSk7CiAgYiA9IHJhbmRvbSgpICUgMTAwICsgMTsKICBuID0gMTA7CgppbnNlcnQoYiwgYSwgJm4pOwoKCiBwcmludGYoIiVkXG4iLCBjaGVja19oZWFwKGEsIDExKSk7CiAKICAKIGZvcihpID0gMDsgaSA8IDExOyBpKyspewoKICAgcHJpbnRmKCIlM2QiLCBhW2ldKTsKCgogfQoKCgoKcmV0dXJuIDA7Cn0KIAppbnQgY2hlY2tfaGVhcChpbnQgYVtdLCBpbnQgbikgewogIGludCBpOwogIGludCBtOwogIG0gP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