BST insert in C++

后端 未结 2 456
南方客
南方客 2021-01-29 04:45

I\'m learning C++ and writing a binary search tree. The following is the code I wrote for my insert method.

BSTNode * BST::Insert(const std::string & v) {
           


        
相关标签:
2条回答
  • 2021-01-29 05:03

    You can change if(n) size++ to if (n != NULL) size++

    0 讨论(0)
  • 2021-01-29 05:10

    Your compiler probably should have spotted this, but this line near the end of your helper:

    if(n->right) Insert_Helper(v,n->right);

    You probably should return whatever Insert_Helper returns:

    if(n->right) return Insert_Helper(v,n->right);

    0 讨论(0)
提交回复
热议问题