Insert a Node at the Tail of a Linked List

  • + 8 comments

    This is my solution in C++14

    Node* Insert(Node *head,int data)
    {
        Node *temp = new Node();
        temp->data = data;
        temp->next = NULL;
       if(head==NULL)
       {
           head = temp;
       }
       else if(head->next==NULL)
       {
                head->next = temp;
                return head;
        }
        else
        {
            Insert(head->next,data);
        }
        return head;
    }