/* * 基础关系:最短编码 * * 自己 00 * 父亲 01 * 母亲 02 * 儿子 11 * female儿 12 * 大哥 21 * 大姐 22 * 小弟 31 * 小妹 32 * 丈夫 41 * 妻子 42 */ public string findRelation(string name1, string name2) //查找name2是name1的什么 { string result = ""; string result_rev = ""; FamilyTreeNode node1 = query(root, name1); FamilyTreeNode node2 = query(root, name2); if (node1 == node2) { return("00"); } if (node1.Level > node2.Level) { while (node1.Level != node2.Level) { node1 = node1.Parent; if (node1.Gender == "male") { result += "01"; } else { result += "02"; } } } else if (node1.Level < node2.Level) { while (node1.Level != node2.Level) { if (node2.Gender == "male") { result_rev += "11"; } else { result_rev += "21"; } node2 = node2.Parent; } } while (isSibling(node1, node2) == -1) { node1 = node1.Parent; if (node1.Gender == "male") { result += "01"; } else { result += "02"; } if (node2.Gender == "male") { result_rev += "11"; } else { result_rev += "21"; } node2 = node2.Parent; } if (isSibling(node1, node2) != 0) { if (node2.Gender == "male") { if (isElder(node1, node2)) { result += "31"; } else { result += "21"; } } else { if (isElder(node1, node2)) { result += "32"; } else { result += "22"; } } } char[] arr = result_rev.ToCharArray(); Array.Reverse(arr); result_rev = new string(arr); result += result_rev; return(result); }
public FamilyTree() { root = null; }
public FamilyTree(string name, int age, string gender, bool isDead, DateTime birthday, string birthplace, DateTime deathday, string height, string education, string profession, string highestProfessionRank) { root = new FamilyTreeNode(name, age, gender, isDead, birthday, birthplace, deathday, height, education, profession, highestProfessionRank); }