the main logic is in operation() function(line 65).Its not printing last element of the linked list that’s why i used two more pointers to print only the last element.Please check if any problem is there.
All test cases not passing
@Aarnav-Jindal-1059677350830863 I have seen this but i have not understood this approach.Can u please rectify my code.I am explaining what i have done ,i am iterating the linked list with two pointers a and b for even and odd respectively.If it is even the value is being inserted into the head of new linked list.Same I have done for the odd values but it is not printing last element that’s why i have taken c and d pointer to print the last element of the linked list.
Its passing two test cases but two are not passing,so there must be any minor mistake.Please can you rectify it?
@supratik260699
You need to use insert at tail instead of insert at head since output for
5
1 2 3 4 5
should be
1 3 5 2 4
And you can see what your output it
Now why I sent you this link is because the approach you’re using while gives right answer but is not the point of the question
This question is based on improving understanding of pointers and you were expected to segregate the nodes and not create new nodes
So even if you get AC now please go to this link and see how to modify the linked list itself without need for creating a new copy and wasting memory
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.