// 2bun-ki
#include <stdio.h>
#include <stdlib.h>
#define height 4
#define MAX (1<<height) //ビットシフト演算 2^height と同じ
int t[MAX+1]; //配列外アクセス防止のためのダミーで+1
int sz = 0;
void initTree(int n){
int i;
for(i=0;i<MAX;i++){
t[i] = -1;
}
}
void printA(){
int i;
for(i
=1;i
<MAX
;i
++) printf("%d ",t
[i
]); }
int goP(int i){
if(i/2 == 0) return 0;
else return i/2;
}
int goL(int i){
if(2*i >= MAX) return 0;
else return 2*i;
}
int goR(int i){
if(2*i+1 >= MAX) return 0;
else return 2*i+1;
}
void insBT(int x){
//ここを書き換える
int k,i=1;
for(k=0; k<height; k++){
if(t[i]==-1){
t[i]=x;
sz+=1;
return;
}
if(x<t[i])
i=goL(i);
else
i=goR(i);
}
printf("Error : too high -> %d\n",x
);
}
int main(void){
int i,x,n;
initTree(n);
for(i=0;i<n;i++){
insBT(x);
}
printA();
return 0;
}
Ly8gMmJ1bi1raQoKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCiNkZWZpbmUgaGVpZ2h0IDQKI2RlZmluZSBNQVggKDE8PGhlaWdodCkgIC8v44OT44OD44OI44K344OV44OI5ryU566XIDJeaGVpZ2h0IOOBqOWQjOOBmAoKaW50IHRbTUFYKzFdOyAvL+mFjeWIl+WkluOCouOCr+OCu+OCuemYsuatouOBruOBn+OCgeOBruODgOODn+ODvOOBp++8i++8kQppbnQgc3ogPSAwOwoKCnZvaWQgaW5pdFRyZWUoaW50IG4pewogICAgaW50IGk7CiAgICBmb3IoaT0wO2k8TUFYO2krKyl7CiAgICAgICAgdFtpXSA9IC0xOwogICAgfQp9Cgp2b2lkIHByaW50QSgpewogICAgaW50IGk7CiAgICBmb3IoaT0xO2k8TUFYO2krKykgcHJpbnRmKCIlZCAiLHRbaV0pOwogICAgcHJpbnRmKCJcbiIpOwp9CgppbnQgZ29QKGludCBpKXsKICAgIGlmKGkvMiA9PSAwKSByZXR1cm4gMDsKICAgI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