You are viewing a single comment's thread. Return to all comments →
Node* Insert(Node *head,int data) { if(head==NULL) { head->data=data; head->next=NULL; } else { Node *p=head; while(p->next!=NULL) { p=p->next; }
Node *x=new Node; x->data=data; x->next=NULL; p->next=x; }
cout<<"Right Answer!"; return head; }
Can anyone please say what I should change in this code to avoid segmentation error?
Seems like cookies are disabled on this browser, please enable them to open this website
Insert a Node at the Tail of a Linked List
You are viewing a single comment's thread. Return to all comments →
Node* Insert(Node *head,int data) { if(head==NULL) {
head->data=data; head->next=NULL; } else { Node *p=head; while(p->next!=NULL) { p=p->next; }
cout<<"Right Answer!"; return head; }
Can anyone please say what I should change in this code to avoid segmentation error?