• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Tree with parents

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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.

 
John Vorwald
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
John Vorwald
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Willie Smits can speak 40 languages. This tiny ad can speak only one:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic