Linked list πŸ’‘ Even-After-Odd

plz check my code it is giving error for two test case.

Hey @sudhanshu8917
Your approach is wrong. Acc to your approach, when you encounter an odd no, you insert it at the head and when you encounter an even no, you insert it at the tail. Now for a test case like:

1 2 4 5 3

your code will give the answer as:
3 5 1 2 4

whereas the correct answer should be:
1 5 3 2 4

because the order of odd numbers and even numbers has to be maintained.So you need to change your approach. Do try this and let me know if you need any help.

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.

what change should i make i cann’t able to understand what you explained me.

@sudhanshu8917
You can try this:
Maintain an even head and an odd head and their corresponding even tail and odd tail, So whenever an even number comes, add it at even tail, and whenever an odd number comes, add it at the odd tail, And join both of them at the end.
You can refer to the following code if you want to(follows the same approach):