Inserting a node into the head of a linked list

For some reason when this code runs it will only run the code in the else statement. I know for certain that head is set to NULL. I am very confused on why this is happening.

code:

void list::insert(string a, string b, int c)
{

if(head = NULL)
{
head = new node;
head->first = a;
head->last = b;
head->age = c;

cout << "First Node has been created" << endl;
cout << "First node has this data: ";
cout << head->first << endl;
cout << head->last << endl;
cout << head->age << endl;
}
else
{
node *n = new node;
n->next = head;
head = n;
n->first = a;
n->last = b;
n->age = c;

cout << "new node added to the first spot in the list" << endl;
cout << "This new node has the following data:";
cout << n->first << endl;
cout << n->last << endl;
cout << n->age << endl;

}
}
Topic archived. No new replies allowed.