• Post Reply Bookmark Topic Watch Topic
  • New Topic

tree interface  RSS feed

 
Alan Chevrier
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
interface Node {
Node getParent();
Node getPriorSibling();
Node getNextSibling();
}

I would like to create a method with the signature as shown below that will return the ID (1.0,1.1,1.1.1,1.1.2,1.1.3,1.2,1.2.1, etc) string of any node object in a given tree that is passed in. The node object has a getID() method. I am not too good with interfaces. Can anyone give me some guidence?

String IDNode (Node) {
}
 
Scott Selikoff
author
Bartender
Posts: 4093
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont think your problem has anything to do with interfaces, you probably want to focus on deciding a Node class.

Other than that, just do some research on a trees in computer science, speficially breadth-first and depth-first searches.
 
Alan Chevrier
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestion. However, the implementation of the "node" class(es) is hidden from me. I only know it implements the Node interface as shown above, and it has a public getID() method. My understanding is lacking in how to implement the method so it accepts any node class that implements this Node interface, and returns the value from the getID() methed of the respective node object.
 
Paul Clapham
Sheriff
Posts: 22831
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The node object has a getID() method.
Well, actually, it doesn't. It has three methods, as specified by the interface, namely getParent(), getPriorSibling(), and getNextSibling(). You did mean the "node" object that implements that "Node" interface, right?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!