logo
  • 教程列表
  • SO官方文檔
  • 二叉搜尋樹
    • 在 BST 中建立節點
    • 將節點插入二叉搜尋樹
  1. StackOverflow 文件
  2. data-structures 教程
  3. 二叉搜尋樹
  4. 將節點插入二叉搜尋樹

將節點插入二叉搜尋樹

Created: November-22, 2018

struct tree{
    int a;
    tree* right;
    tree* left;
};
tree* root=NULL;
void insert(tree*& in, int b){
        if(in){
            if(in->a<b)
                    insert(in->right,b);
            else if(in->a>b)
                    insert(in->left,b);
            else
                cout<<"the value is already in the tree."<<endl;
        }else{
            tree* temp = new tree;
            temp->a=b;
            temp->right=NULL;
            temp->left=NULL;
            in=temp;
        }
}
  • 在 BST 中建立節點

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明