Comparing family member nodes in C++

542 views Asked by At

I have been working on a family SinglyLinked list. I seemed to be unable to compare the family member.

The node consists of the following:

class Node{
public:
    int id, age;
    string name;
    char sex;
    string father, mother;

Node* next;
};

The code implementation:

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

There are 0 answers