X292: Binary Tree Set Depth Exercise

Write a recursive function to set the value for each node in a binary tree to be its depth. Assume that nodes store integer values. On the initial call to BTsetdepth, "depth" is 0.

Examples:

BTsetdepth((new BinaryTree({"4", "1", "3", "NULL", "NULL", "NULL", "2", "NULL", "8", "NULL","NULL"}
 )).root,0) -> (new BinaryTree({"0", "1", "2", "NULL", "NULL", "NULL", "1", "NULL", "2",
 "NULL","NULL"})).root

Your Answer:

Reset

Feedback

Your feedback will appear here when you check your answer.