Due to reasons beyond my control, the function declaration must not change. I'm not very good with pointers, so the NODE** declaration really throws me off.
I know the basic gist is more or less correct. I just keep getting errors due to the pointers and don't know how to solve it.
There is currently an error in this line of the else statement:
NODE* last = data;
//a value of type "NODE **" cannot be used to initialize an entity of type "NODE *"
Yet I don't know if I've been handling the pointers correctly.
class NODE {
public:
string firstname;
string lastname;
string email;
NODE* next;
};
void add_node_tail(NODE** data, string firstname,string lastname, string email) {
NODE* temp = new NODE;
temp->firstname = firstname;
temp->lastname = lastname;
temp->email = email;
temp->next = NULL;
if(!data) { // empty list becomes the new node
data = &temp;
return;
} else { // find last and link the new node
NODE* last = data;
while(last->next) {
last=last->next;
last->next = temp;
}
}
}
If you could give me a rundown of how the pointers would work in the correct implementation, that would be the perfect answer.