Family tree using Tree

  • (4 Pages)
  • +
  • « First
  • 2
  • 3
  • 4

51 Replies - 7253 Views - Last Post: 25 July 2012 - 02:12 PM

#46 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1396
  • View blog
  • Posts: 4,858
  • Joined: 19-February 09

Re: Family tree using Tree

Posted 23 July 2012 - 06:22 PM

Hopefully, your teacher wants a simple family tree.

With the first insertion the root pointer will be null (because it was so initialised by you the programmer). In that case three nodes are inserted, the child and two parents.

With the next insertion the root is not null. Only the two parents are inserted linked to an already existing child.
Was This Post Helpful? 0
  • +
  • -

#47 jayburn00  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 129
  • Joined: 05-July 12

Re: Family tree using Tree

Posted 24 July 2012 - 11:16 AM

View Post#define, on 23 July 2012 - 06:22 PM, said:

Hopefully, your teacher wants a simple family tree.

With the first insertion the root pointer will be null (because it was so initialised by you the programmer). In that case three nodes are inserted, the child and two parents.

With the next insertion the root is not null. Only the two parents are inserted linked to an already existing child.

Actually that is where he said we should start. The finished product is more complex.
Was This Post Helpful? 0
  • +
  • -

#48 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3646
  • View blog
  • Posts: 11,412
  • Joined: 05-May 12

Re: Family tree using Tree

Posted 24 July 2012 - 08:21 PM

And after the insertion, the check for "spouse" becomes interesting. If two nodes share a common child, they are "married".

       Dummy
      /     \
  George   Thomas
   |    \ /   |
   |     X    |
   |    / \   |
  Martha   Henry



If Martha and Henry share Thomas as a common child, then Martha and Henry must be married.
If Martha and Henry share George as a common child, then Martha and Henry must be married.
If George and Thomas share Dummy as a common child, then George and Thomas must be married.
Was This Post Helpful? 0
  • +
  • -

#49 jayburn00  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 129
  • Joined: 05-July 12

Re: Family tree using Tree

Posted 25 July 2012 - 09:47 AM

View PostSkydiver, on 24 July 2012 - 08:21 PM, said:

And after the insertion, the check for "spouse" becomes interesting. If two nodes share a common child, they are "married".

       Dummy
      /     \
  George   Thomas
   |    \ /   |
   |     X    |
   |    / \   |
  Martha   Henry



If Martha and Henry share Thomas as a common child, then Martha and Henry must be married.
If Martha and Henry share George as a common child, then Martha and Henry must be married.
If George and Thomas share Dummy as a common child, then George and Thomas must be married.



I know, it seems pretty silly. Is there any way to make it so that dummy nodes are excepted from the rule?
Was This Post Helpful? 0
  • +
  • -

#50 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3646
  • View blog
  • Posts: 11,412
  • Joined: 05-May 12

Re: Family tree using Tree

Posted 25 July 2012 - 11:11 AM

You'll probably need a "fIsDummy" boolean on each node. If the child is a dummy, then it's not their kid. (I wonder how many parents have secretly thought this. :lol:)

As I said, with dummy nodes, you'll need to start doing special cases.

This post has been edited by Skydiver: 25 July 2012 - 11:12 AM

Was This Post Helpful? 0
  • +
  • -

#51 jayburn00  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 129
  • Joined: 05-July 12

Re: Family tree using Tree

Posted 25 July 2012 - 02:09 PM

Any other way of doing it? By the way, the teacher provided a data file to test our code, but I pointed out that his file would not work because some of the people had the same name. It was meant to be a family tree of George Washington. He did not use last names, so that caused some weirdness, and he accidently set a male as being female in the data file also. I looked at Washington's real tree though, the one the teacher used to come up with his data file and interestingly, it would have worked as a binary tree, because in it, GW had no siblings. Unfortunately, he is using something else now. I should have kept my mouth shut and that would have made everyone's code not work. Now I helped correct it, but still don't have any code. Isn't that a laugh. Anyway, I need to turn something in. How would I go about using the data file for input into a tree(I know how to read eachline of the file, but not how to get those lines to do what they need to do.
Was This Post Helpful? 0
  • +
  • -

#52 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10767
  • View blog
  • Posts: 40,090
  • Joined: 27-December 08

Re: Family tree using Tree

Posted 25 July 2012 - 02:12 PM

Our members have spent four pages explaining how trees work, as well as File I/O. The trick is to keep them separate. Your Tree class should handle all the Tree operations. Just pass the appropriate objects to the insert() function.

In terms of how to write the Insert, I think our members have explained this quite thoroughly.
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • « First
  • 2
  • 3
  • 4