My task is to calculate depth of each node and store it in 'depth' given in Node class. But I don't know how I should approach this task. I was looking for some example in the internet but haven't found any appropriate to my task. This is the code of my given Node class:
Node
{int value; Node left, right; int depth;}
I thought I could use a similar method to counting height of a tree but it didn't work out. Any help?
Call with
updateDepth(root, 0);