Why do we need to pass it by reference, for example, to push (node * & head, int key)
Otherwise, the set value will not be set linkNodeas the current one head:
if(head==NULL)
{
linkNode->next=NULL;
head=linkNode;
}
You have a link to a pointer ( head) that will be "returned" from the function push(), and set the pointer headpassed from the caller correctly:
node* head=NULL;
push(head,2);
delete node, new node();. , , .