Regarding the wrong output
Your Approach is NOT correct
we you want to make a new list then don’t do like this
you have to create complete new node
otherwise links in original list will affected
dry run this code , you will understand better
2 Approaches to solve this ques
- make completely new(means create new nodes) linked list , odd and even list
OR - use partition approach
Partition Approach
https://ide.codingblocks.com/s/573212