my merge function is correct but my linked list is not taking inputs, please help
Merge two linked list
Hello @WARHEAD,
Your builtN() function is logically incorrect.
Explanation:
After reading the element of the first linked list.
The element( stored in data) will be inserted to the linked list by passing it to InsertAtTail(head, data); (in the next iteration of the while loop).
Thereafter, cin>>data; will execute and read the size of the second linked list in the variable data.
Which is causing wrong output.
Modified Code:
void buildN(node*& head, int n)
{
int data;
//cin>>data;
while(n!=0)
{
cin>>data;
InsertAtTail(head, data);
//cin>>data;
n–;
}
}
Hope, this would help.
Give a like if you are satisfied.
still getting a wrong answer please tell me what is wrong
Hello @WARHEAD,
This is because your merge function is not logically incorrect.
I have corrected your code:
Hope, this would help.
Give a like if you are satisfied.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.