roseying 2020-02-14
//二叉链表
struct node{
    typename data;
    node* lchild;
    node* rchild;
};
//如果二叉树在建树前根结点不存在,因此其地址一般设为NULL
node* root = NULL;
//如果想要新建结点,可以使用一下函数
node* newNode(int v){
    node* Node = new node;
    Node->data = v;//结点权值
    Node->lchild = Node->rchild = NULL;//初始状态下没有左右孩子
    return Node;//返回新建结点的地址
}void search(node* root, int x, int newdata){
    if(root == NULL){
        return;//递归边界
    }
    if(root->data == x){
        root->data = newdata;
    }
    search(root->lchild, x, newdata);
    search(root->rchild, x, newdata);
}void insert(node* &root, int x){
    if(root == NULL){//递归边界
        root = newNode(x);
        return;
    }
    if(由二叉树的性质,x应该插在左子树){
        insert(root->lchild, x);
    }else{
        insert(root->rchild, x);
    }
}node* Create(int data[], int n){
    node* root = NULL;
    for(int i = 0; i < n; i++){
        insert(root, data[i]);
    }
    return root;
}