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)
Node *newn=(Node *)malloc(sizeof(Node));
Node *newn2=(Node *)malloc(sizeof(Node));
newn2->next=Insert(newn2->next , data);
thanks! nice one!
you can reduce complexity by removing while loop there, because anyway in recursion head moves as you pass newn2->next, so no need to check the condition whether it is pointing to the extreme