node结构体数组建树写法
指针建树及题意思路详见:https://blog.csdn.net/xiang_6/article/details/100128763
#include<bits/stdc++.h>
#include<cstring>
#define FI first
#define SE second
using namespace std;
typedef long long ll;
typedef pair<string, string> P;
const int maxn = 100 + 7;
int n, a[maxn];
struct node {
int v, f = -1;
int l, r;
}t[maxn];
void ins(int id, int pos, int va) {
if(abs(va) <= abs(t[id].v)) {
if(t[id].l == -1) {
t[id].l = pos;
t[pos].f = 1;
t[pos].v = va;
}
else ins(t[id].l, pos, va);
}
else {
if(t[id].r == -1) {
t[id].r = pos;
t[pos].f = 1;
t[pos].v = va;
}
else ins(t[id].r, pos, va);
}
return;
}
void init() {