在C ++中比较家庭成员节点

时间:2014-11-22 02:13:51

标签: c++ data-structures singly-linked-list family-tree

我一直致力于家庭SinglyLinked列表。我似乎无法比较家人。

该节点包含以下内容:

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;
}

0 个答案:

没有答案