看板 C_and_CPP 關於我們 聯絡資訊
※ 引述《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