Insert a Node at the Tail of a Linked List

  • + 0 comments

    This is becase when you used Node *temp, you just made a pointer of type Node, No memory was allocated as in the pratik9044536615's code where he uses

    new Node();
    

    So, I would suggest allocating memory either using new Node() or go all C style and use

    Node *temp = (Node  *)malloc(sizeof(Node));