int BSTree<DataType, KeyType>::countHelper(BSTreeNode *parent) const { if(parent == NULL) { return 0; } return countHelper(parent->left) + countHelper(parent->right) + 1; }
int countNumbersWithUniqueDigits(int n) { if (n == 0) return 1; std::function<int(int)> countHelper = [&](int k) -> int { if (k == 1) return 10; if (k > 10) k = 10; int num = 9; for (int i = 0; i < (k-1); ++i) num *= (9-i); return num + countHelper(k-1); }; return countHelper(n); }
int BST::countHelper(Node *node){ if(node == NULL){ return 0; } else return 1+countHelper(node->left)+countHelper(node->right); }
int BSTree<DataType, KeyType>::getCount() const { return countHelper(root); }
//Count nodes in a BST int BST::count(){ return countHelper(root); }