#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
struct node{
int data;// 数据域
int lchild; // 指向左子树的指针域
int rchild; // 指向右子树的指针域
}Node[maxn]; // 节点数组,maxn为节点上限个数
int index = 0;
int newnode(int v)// 分配一个Node数组中的节点给新的节点,index 为其下标
{
Node[index].data = v;// 数据域为v
Node[index].lchild = -1;
Node[index].rchild = -1; // 以-1或maxn表示空,因为数组范围是0~maxn-1
return index++;
}
void search(int root,int x,int newdata)
{
if(root == -1){
return;
}
if(Node[root].data == x){
Node[root].data = newdata;
}
search(Node[root].lchild,x,newdata); // 往左子树搜索x
search(Node[root].rchild,x,newdata); // 往右子树搜索x
}
// 插入,root 为根节点在数组中的下标
void insert(int &root,int x){
// 记得加引用
if(root == -1){
// 空树, 说明查找失败, 也就是插入位置
root = newNode(x); // 给root赋以新的节点
return;
}
if(由二叉树的性质x应该插在左子树){
insert(Node[root].lchild,x); // 往左子树搜索
}
else{
insert(Node[root].rchild,x); // 往右子树搜索
}
}
// 二叉树的建立,函数返回根节点root的下标
int Create(int data[],int n){
int root = -1; // 新建根节点
for(int i = 0; i < n; i++){
insert(root,data[i]); // 将data[0]~data[n-1] 插入二叉树中
}
return root; // 返回二叉树的根节点下标
}
void preorder(int root){
if(root == -1){
return; // 到达空树,递归边界
}
// 访问根节点root,例如将其数据域输出
cout << Node[root].data << endl;
preorder(Node[root].lchild);
preorder(Node[root].rchild);
}
int main()
{
return 0;
}