作者adrianshum (Alien)
看板C_and_CPP
标题Re: [问题] 祖谱的结构
时间Thu Feb 19 10:27:47 2009
※ 引述《smilecylin (unicharm)》之铭言:
: 刚刚想到一个类似祖谱的资料结构不知道该怎麽实现
: Mary是Judy的妈妈,以此类推
: Judy -> Mary -> Alice -> Linda -> Cindy -> Diana
: Elma
: Peoplerelationship A; //假设A为Alice
: cout << A.mother.mother << endl; // Cindy
: cout << A.daughter(0).mother.daughter(1) <<endl; // Elma
: 简单的是像这样再复杂的话就是又有兄弟姐妹之类的
: 如A.mother.brother(1).daughter(0)
: 有人可以起个头吗?
通常不外乎
class Person {
vector<Person*> offsprings; // 指向所有儿子
// Person* parent; // 视乎需要加不加
}
或是
class Person {
Person* sibling; // 指向弟弟
Person* offspring; // 指向第一个儿子
// Person* parent; // 视乎需要
}
看哪种做法比较适合你了
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 202.155.236.82