Do I need to take the whole list first and then rearrange them or I can also arrange them accordingly while taking in the input???
Even-after-Odd problem
No take the whole list first as it is. And then rearrange.
There is no need of a tail pointer. Just traverse the linked list from the start and if you find an even number, push it to the end of the linked list. That’s it.
And to avoid any repetitions, you can use a map.
Also dry run your code for the following linked lists -
1 1 1 2
1 2 2 1
You will get to know about your mistake.
Thanks a lot for the help, can you please tell me what a map is, or give me some reference or link to study it from a source which explains it properly
http://www.cplusplus.com/reference/map/map/
You can study from these two sources. These will be sufficient.
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.
Thanks a lot for the help and to suggest the sorce
The code isn’t passing all the test cases, though it appears to be right
Can you pls tell what I am not considering
@Tushar-Goel-1587999611286693 What you are doing will change the relative ordering of the numbers
Like 2 3 5 4 Will become 5 3 2 4 Whereas the correct output would be 3 5 2 4
Here have a look at this code. If this resolves your doubt mark it as resolved.
Thanks a lot to tell about the mistake