In function append pointer h1 is not changed
In function insertAtHead head should be changed but instead of that a local variableis changed. You should take into account that parameters are local variables of the function. So after exiting the function all local variables are destroyed.
You could get the same effect if function append deal with an empty list. In this case you had to allocate the head inside the function and these changes of head would not influence the original head.
There are three approaches to write these functions correctly. Either each function returns updated head or the head must be passed either by reference or indirectly by pointer to head.
Consider for example how function append would work if the list was empty i.e. when the first argument is equal to NULL.
void append(Node* h1, Node* h2)
{
cout << h1 << ":" << h2;
cout << endl;
if ( h1 == NULL )
{
h1 = h2;
}
else
{
Node *ptr = h1;
while ( ptr->next != NULL) ptr = ptr->next;
ptr->next = h2;
}
}
As you see in this case it would have the same error as function insertAtHead. Changes of h1 inside the function would not influence the original value of head. Only local variable h1 would be changed and after that destroyed after exiting the function. Original variable head would keep the same old value as before.