写的非常丑陋(
#include<bits/stdc++.h>
using namespace std;
typedef struct BitNode {
int data;
struct BitNode *lchild, *rchild;
} node, *btree;
int cnt[10];
void print(int a,int b,int c){
printf("%d %d %d\n",a,b,c);
}
void preorder(btree root) {
if (root == NULL) return;
cout << root->data << ' ';
preorder(root->lchild);
preorder(root->rchild);
}
void midorder(btree root) {
if (root == NULL) return;
midorder(root->lchild);
cout << root->data << ' ';
midorder(root->rchild);
}
void lastorder(btree root) {
if (root == NULL) return;
lastorder(root->lchild);
lastorder(root->rchild);
cout << root->data << ' ';
}
void bfs(btree root){
queue<btree>q;
q.push(root);
while(q.size()){
auto t = q.front();
cout<<t->data<<' ';
q.pop();
auto l = t->lchild , r = t->rchild;
if(l!=NULL)q.push(l);
if(r!=NULL)q.push(r);
}
}
int height(btree root){
if(root==NULL)return 0;
int l = height(root->lchild);
int r = height(root->rchild);
print(root->data,l,r);
return max(l,r)+1;
}
void wight(btree root,int h){
if(root==NULL)return;
wight(root->lchild,h+1);
wight(root->rchild,h+1);
cnt[h]++;
}
int sum=0;
void wpl(btree root,int h){
if(root==NULL)return;
if(root->lchild==NULL&&root->rchild==NULL)sum+=root->data*h;
wpl(root->lchild,h+1);
wpl(root->rchild,h+1);
}
bool dfs(btree root){
if(root->lchild&&root->rchild&&root->lchild->data>=root->rchild->data)return false;
if(root->lchild)if(!dfs(root->lchild))return false;
if(root->rchild)if(!dfs(root->rchild))return false;
return true;
}
int main() {
// Allocate memory for the nodes
node *root = new node();
node *l = new node();
node *r = new node();
node *c = new node();
node *d = new node();
// Initialize the data for root and its children
root->data = 1;
root->lchild = l;
root->rchild = r;
l->lchild = NULL;
l->rchild = NULL;
l->data = 3;
r->lchild = NULL;
r->rchild = c;
r->data = 2;
c->data=4;
c->rchild = NULL;
c->lchild = d;
d->data = 5;
d->lchild = NULL;
d->rchild = NULL;
// Perform tree traversals
// preorder(root); puts("");
// midorder(root); puts("");
// lastorder(root); puts("");
// bfs(root);
// Clean up dynamically allocated memory
// wight(root,1);
// int mx=0;
// for(int i=1,n=height(root);i<=n;i++){
// mx=max(mx,cnt[i]);
// print(i,cnt[i],mx);
// }
//
// wpl(root,0);
// cout<<sum;
cout<<dfs(root);
delete root;
delete l;
delete r;
delete c;
return 0;
}