Deleting a node in a family tree
Posted
by
user559142
on Stack Overflow
See other posts from Stack Overflow
or by user559142
Published on 2011-01-06T11:52:21Z
Indexed on
2011/01/06
11:53 UTC
Read the original article
Hit count: 221
Hi,
I'm trying to calclulate the best way to delete a node in a family tree. First, a little description of how the app works.
My app makes the following assumption:
Any node can only have one partner. That means that any child a single node has, it will also be the partner nodes child too. Therefore, step relations, divorces etc aren't compensated for. A node always has two parents - A mother and father cannot be added seperately. If the user doesn't know the details - the nodes attributes are set to a default value.
Also any node can add parents, siblings, children to itself. Therefore in law relationships can be added.
I have the following classes:
FamilyMember
String fName; String lName; String dob; String gender; FamilyMember mother, father, partner; ArrayListchildren; int index; int generation;
void linkParents(); void linkPartner(); void addChild();
//gets & sets for fields
Family
ArrayListfamily;
void addMember(); void removeMember(); FamilyMember getFamilyMember(index); ArrayListgetFamilyMembers();
FamilyTree
Family family;
void removeMember(); //need help void displayFamilyMembers(); void addFamilyMember(); void enterDetails(); void displayAncestors(); void displayDescendants(); void printDescendants(); FamilyMember findRootNode(); void sortGenerations(); void getRootGeneration();
I am having trouble with identifying the logic for removing a member. All other functions work fine. Has anyone developed a family tree app before who knows how to deal with removing various different nodes in the family "tree"?
e.g. removing a leaf removing a leaf with partner (what if partner has parents etc) removing a parent
It seems to be another recursive property but my head is swelling from over thought.
© Stack Overflow or respective owner