阅读背景:

该函数不会向我的bst树添加任何内容

来源:互联网 
class node{
public:
    int data;
    node *left;
    node *right;
};

class BFStree{
public:
    void insert(int key);
    void deleteNode(int key);
    void inorderTraversal(node *temp);
    void inorder();
    node *root;
    BFStree(){
        root = NULL;
    }
};

 void BFStree::insert(int key){
    node *temp = root;
        while(temp!=NULL){
            if(key>temp->data){
                temp = temp->right;
            }
            else if(key<temp->data){
                temp = temp->left;
            }
            else{
                cout << "NOT ALLOWED TO HAVE SAME DATA" << temp->data << " " << key << endl;
            }
        }
        node *temp2 = new node;
        temp2->data = key;
        cout << key << " inserted" << endl;
        temp2->left = NULL;
        temp2->right = NULL;
        temp = temp2;
    }

int main(){
    BFStree t;
    t.insert(7);
    t.insert(3);
    t.insert(21);
}
class node{
public:
    int data;
    node *lef



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: