i have a doubt regarding classes.Please look at the codebyte below. the program runs fine but when i keep child_node instead of child_node.value() in line 8 it throws an error. why?
In trees, nodes are objects. Children and parent nodes therefore are objects as well. Unlike arrays, there is no index that any given node can point to and say go there. Once you are at a given node, you only have access to: 1. that node, 2. its children, 3. its parents.
If instead of an object the children and parents were values, the following would happen. You start at node A, and you say one of the child’s value is 15. But then what about the value of the child’s child? You can’t manipulate the value 15 to give you that.
Thanks for the detailed explanation. It didn’t occur to me that if the child and parent were values i couldn’t link or connect two nodes.
You can link them, just not by value