I got a code for finding the single target ancestor in a BST. How can I change it to become finding all the ancestors wihtout any target in the BST. Basically just print out all the node that has sons. Thank you
bool BST<T>::printAncestor(T item)
{
/* base cases */
if (root == NULL)
returnfalse;
if (root->data == target)
returntrue;
/* If target is present in either left or right subtree of this node,
then print this node */
if (printAncestors(root->left, target) ||
printAncestors(root->right, target))
{
cout << root->data << " ";
returntrue;
}
/* Else return false */
returnfalse;
}
In a class declaration, the keywords class and struct are synonyms, except that:
With the keyword class, the default member-access (and the default base-class-access) is private
With the keyword struct, the default member-access (and the default base-class-access) is public
class A { public: /* ... */ }; and struct A { /* ... */ }; are equivalent.
class A { /* ... */ }; and struct A { private: /* ... */ }; are equivalent.