I have written this code to insert node at the end of singly linked-list. It compiles without errors but upon execution no output shows. Where have i gone wrong?
void insert_n(int x){
node* temp1 = new node();
temp1->data=x;
temp1->next=NULL;
node* temp2 = head;
while(temp2->next!=NULL){
    temp2 = temp2->next;
}
temp2->next=temp1;
}
void print(){
node* temp = head;
while(temp!=NULL){
    cout<<temp->data<<" ";
    temp = temp->next;
}
}
int main()
{
    head = NULL;
    insert_n(2);
    insert_n(3);
    insert_n(4);
    insert_n(5);
    print();
    return 0;
}
Does it fail because there should be a special case for when the list is empty?
 
     
     
    