diff --git a/thu_dsa/chp5/binNode.h b/thu_dsa/chp5/binNode.h index d6de521..9e02c22 100644 --- a/thu_dsa/chp5/binNode.h +++ b/thu_dsa/chp5/binNode.h @@ -68,7 +68,7 @@ void BinNode::goAlongLeftBranch(Stack &S){ template int BinNode::size() const { int leftSize = this->leftChild ? this->leftChild->size() : 0; - int rightSize = this - rightChild ? this->rightChild->size() : 0; + int rightSize = this -> rightChild ? this->rightChild->size() : 0; return leftSize + rightSize + 1; } diff --git a/thu_dsa/chp5/testBinTree.cpp b/thu_dsa/chp5/testBinTree.cpp index b01544a..3d50704 100644 --- a/thu_dsa/chp5/testBinTree.cpp +++ b/thu_dsa/chp5/testBinTree.cpp @@ -6,6 +6,7 @@ using std::cout; using std::endl; void test_insert(); +void test_size(); void test_preTraversal(); void test_inTraversal(); void test_postTraversal(); @@ -15,6 +16,7 @@ int main(){ cout << "Running test." << endl; test_insert(); + test_size(); test_preTraversal(); test_inTraversal(); test_postTraversal(); @@ -56,6 +58,16 @@ void test_insert(){ assert(left->height == 0 && right->height == 0); } +void test_size(){ + BinTree intTree; + BinNodePosi(int) root = intTree.insertAsRoot(8); + assert(root->size() == 1); + intTree.insertAsLC(root, 7); + assert(root->size() == 2); + intTree.insertAsRC(root, 14); + assert(root->size() == 3); +} + template struct Print{ virtual void operator()(T const &val){