void test_tree() { TreeNode<int> *root = tree_node_new<int>(); root->data = 0; TreeNode<int> *node1 = append_child(root, 1); /*TreeNode<int> *node2 = */append_child(root, 2); /*TreeNode<int> *node3 = */append_child(root, 3); /*TreeNode<int> *node4 = */append_child(node1, 4); TreeNode<int> *node5 = append_child(node1, 5); /*TreeNode<int> *node6 = */append_child(node5, 6); preorder2(root, PrintFunc()); }
void BSTree :: preorder2(int *count,struct BSTreeNode *t) { //static int i = 0; if(t == NULL) { return; } //i = i +1; //cout<<endl<<i; if(t->right != NULL && t->left != NULL) *count = *count + 1; if(t->right != NULL && t->left == NULL) *count = *count +1; if(t->left != NULL && t->right == NULL) *count = *count + 1; //cout<<"\n"<<arr[i]; //cout<<endl<<*count; preorder2(count,t->left); preorder2(count,t->right); //*count =i; //cout<<"\n count "<<*count; }
int BSTree :: count_non_leaf_nodes(void) { int count = 0; preorder2(&count,root); return count; }