我一直在处理一个家庭单链接列表。我似乎无法比较家庭成员。
该节点由以下部分组成:
class Node{
public:
int id, age;
string name;
char sex;
string father, mother;
Node* next;
};
代码实现:
Node* currNode = head;
Node* prevNode = NULL;
int index = 1;
//while the current node and the current nodes name is not string one
//n1 and n2 are strings
while(currNode && currNode->name != n1 && prevNode && prevNode->name !=n2){
prevNode = currNode;
currNode = currNode->next;
index++;
}
if(currNode->father == prevNode->name){
cout<<prevNode->name<<" is the father"<<endl;
}