sir, can tom please tell me what is MLE error and why my code is showing this error
Regarding merging list
your approach is not correct
lets take an example
1
5
1 2 5 6 8
3
4 10 11
in this case h1 points to 1 h2 points to 4
now h1 point to 2 h2 points to 4 and h3 points to 1
now inside while loop
while (head1 != NULL and head2 != NULL)
{
if (head1->data > head2->data)
{
temp->next = head2;
head2 = head2->next;
temp = temp->next;For that follow this approach
 Regarding merging list
your
}
else
{
temp->next = head1;
head1 = head1->next;
temp = temp->next;
}
}
you make new links
temp->next = head1; and temp->next = head2;
they change the whole linked list
correct approach
node* merge(node *a, node *b) {
if (a == NULL) {
return b;
}
else if (b == NULL) {
return a;
}
node *c = NULL;
if (a->data < b->data) {
c = a;
c->next = merge(a->next, b);
}
else {
c = b;
c->next = merge(a, b->next);
}
return c;
}
actually i have taken the sorted array in mind but by mistake it was done
8 should come at end
i have correct it now
the problem with your approach is
you are creating new links to the orginal linked list due to which you are getting error
i have expalined it above
make dry run to this example you will understand it
NOTE
if you have more doubts regarding this question you can ask it here i will reply you every time
no need to ask doubt again and again seperately
sir with your code also it is showing MLE ERROR
problem is not with function i have provided
it is with your built function
in built function add one condition
if(p<=0) {
head=NULL;
return;
}