3 Replies - 14011 Views - Last Post: 28 May 2007 - 08:08 AM Rate Topic: -----

#1 aissamt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-May 07

family tree using java

Posted 27 May 2007 - 11:15 AM

i have a project to constract a family tree using java, i tried to do it , but no chance, if you have any clues on how to do it, please post it, thx
Is This A Good Question/Topic? 0
  • +

Replies To: family tree using java

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: family tree using java

Posted 27 May 2007 - 11:34 AM

It would be better if you post the code that you completed in your attempt to fulfill your project.

We do not provide code just for the asking, we help you understand what is wrong with your code.
Was This Post Helpful? 0
  • +
  • -

#3 aissamt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-May 07

Re: family tree using java

Posted 27 May 2007 - 03:32 PM

all i need is how to do the find methode, since every node in the tree can have many children ( so i used an array for it) but now i can't figure a way to search the whole tree for a specific node.
Was This Post Helpful? 0
  • +
  • -

#4 oubless  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 28-May 07

Re: family tree using java

Posted 28 May 2007 - 08:08 AM

View Postaissamt, on 27 May, 2007 - 03:32 PM, said:

all i need is how to do the find methode, since every node in the tree can have many children ( so i used an array for it) but now i can't figure a way to search the whole tree for a specific node.

- consider using java.util.List instead of array.
- about the search method:
Make it recursive, something like ( this will probably NOT work as is )
 
public Node find(Node nodeToFind){
  Node tmp;
  if( this.equals(nodeToFind) )
	 return this; // found - this one
  for( Node child : childrenNodes ){
	tmp = child.find(nodeToFind);
	if( tmp != null ) // found in some of the children nodes 
	   return tmp;
  }
  return null; //not found
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1