You are viewing a single comment's thread. Return to all comments →
my program is the same as yours except the first part of the code where mine says
Node *temp; //did not use Node*temp=new Node
This is causing error in my code.. Can you please explain?
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
So, I would suggest allocating memory either using new Node() or go all C style and use
Node *temp = (Node *)malloc(sizeof(Node));