I read a few more articles that looked similar, but didnโt quite answer my problem. I was asked about the assignment to assign each node in the binary tree the corresponding depth. I just can't get it.
For reference, this is my code:
struct treeNode { int item; int depth; treeNode *left; treeNode *right; }; typedef treeNode *Tree; int assignDepth(Tree &T, int depth) { if(T!=NULL) { depth = assignDepth(T->left, depth++); T->depth = depth; depth = assignDepth(T->right, depth++); } else
I tried to start it with a pen and paper, and everything looked fine, but I obviously lacked the skills to check the table.
Can someone point me in the right direction please? This is my first time using trees, and recursion is not my forte.
Answer:
void treecoords(Tree &T, int depth) { static int count = -1;
c ++ recursion binary-tree
xyzjace
source share