Insert a Node at the Tail of a Linked List

  • + 2 comments
    Node *temp = new Node();
    temp->data=data;
    temp->next=NULL;
    
    if(head==NULL)
    {
        head=temp;
    }
    else
    {
        Node *current=head;
    while(current->next!=NULL)
        {
            current=current->next;
        }
    current->next=temp;
     }
    
    return head;