I have a tree structure that uses a list of nodes for the children, along with a reference to the parent.
I would like to be able to extract a node incorporating the data from the ancestors of a node.
But, I don't know how to call a member of the generic class.
I have an alternative solution where the generic class contains a reference to a tree node, and can access the parent, so the generic class can construct the summary.
In the alternative solution, I don't get the expected result of "Beginning of the week", 6. The output is "week", 3.
The alternative solution had a error in the incorporateParent member. The correction is below.
But, I'd still prefer to use the first alternative, to have the tree/node class manage incorporating ancestors data, instead of passing the tree node to the generic class.
I dug a little deeper into how the treenode class could be modified to manage the incorporating of ancestors. One approach to allow a generic function to call a specific member function is to make the generic extend an interface that defines the function.
The following code is an example of a tree that is able to incorporate data from ancestor nodes. It produces the result "Beginning of the week", 6, which is the desired result.
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.
a bit of art, as a gift, that will fit in a stocking