Generic tree problem

How to print a generic tree

Hey @Ajitverma1503
The recursive code to print a generic tree can be written as:

void printGenericTree(TreeNode* root){
    if(root == NULL) return;
    
    cout << root->data << " ";
    
    for(int i = 0; i < childrenVector.size(); i++){
          printGenericTree(root->childrenVector[i]);
    }
}

First root is printed, then the children are printed recursively the whole tree gets printed.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.