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.
51 Replies - 2951 Views - Last Post: 25 July 2012 - 02:12 PM
#47
Re: Family tree using Tree
Posted 24 July 2012 - 11:16 AM
#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.
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.
#48
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".
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.
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.
#49
Re: Family tree using Tree
Posted 25 July 2012 - 09:47 AM
Skydiver, 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".
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.
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?
#50
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.
)
As I said, with dummy nodes, you'll need to start doing special cases.
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
#51
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.
#52
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.
In terms of how to write the Insert, I think our members have explained this quite thoroughly.
|
|

New Topic/Question
Reply




MultiQuote






|