Insert a Node at the Tail of a Linked List

  • + 27 comments

    Please suggest , unable to find out mistake in this :

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

    Showing no response in output :(