You are viewing a single comment's thread. Return to all comments →
you have not covered the condition where the head is null. if you want to do this in this manner , your code should be somthing like this:
Node* Insert(Node *head,int data) { if(head==NULL) { Node *newn=(Node *)malloc(sizeof(Node));
newn->next=NULL; newn->data=data; head=newn; } else{ Node *newn2=(Node *)malloc(sizeof(Node)); newn2=head; while(newn2->next!=NULL){ newn2=newn2->next; } newn2->next=Insert(newn2->next , data); } return head;
}
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 →
you have not covered the condition where the head is null. if you want to do this in this manner , your code should be somthing like this:
Node* Insert(Node *head,int data) { if(head==NULL) { Node *newn=(Node *)malloc(sizeof(Node));
}