Considering you've node
with reference of parent_node
then function deep
could implemented as follows:
(Each node has id & data property)
int deep(node *n) { /* deep of root node is zero and that's our base case */ if(n->parent_node.id == 0) return 0; return 1 + deep(n->parent_node);}