Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am stumped on this problem: write a function template <typename T> int countOn

ID: 3633423 • Letter: I

Question

I am stumped on this problem:

write a function

template <typename T>
int countOneChild(tnode<T> *t);

that counts the number of interior nodes in a binary tree having one child. Test the function in a program that uses buildTree() from "d_tnodel.h" to allocate Tree 1 and Tree 2. Call countOneChild() for each tree, and output the results.

if anyone can help, it would be greatly appreciated!

Explanation / Answer

// Aaron Johnston // CSIS 3402/01 // 07/06/06 // Problem # 35 // Page # 579 // This is a driver program that tests a function countOneChild // The function counts the number of interior nodes in a // binary tree having one child. The function will be tested in // a program that uses buildTree() from "d_tnode1.h" to allocate // Tree 1 and Tree 2. The function countOneChild() will be called // once for each tree, and output the results. #include #include #ifndef NULL #include #endif // NULL #include "d_tnode.h" // tnode class #include "d_tnodel.h" // tnode library using namespace std; template int countOneChild(tnode *t) { int oneChildCount; if (t != NULL) // If it were NULL there would be no one child nodes! { if ((t->left != NULL && t->right == NULL) || (t->left == NULL && t->right != NULL)) // associate the condition with the incrementation of a variable, // that is to say if child has only one node oneChildCount should // increase by 1, store the value, and be able to increase again if // necessary // HOWEVER oneChildCount++ returns large numbers // oneChildCount++; else // This statement confirms that one child nodes are actually // being found. And that two and zero child nodes exist. cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote