Why this code is throwing segmentation fault?
i was trying to maintain two pointer, one pointing to the end of odd ans another pointing to the beginning of even. whenever we see odd number on even pointer, we exchange it with the next of odd pointer.
even pointer will traverse the whole linkedlist, and whenever it sees odd number, it get exchanged.

this might be null as well , so handle that case.
for example. let say we have only head node.
then u will try to access data of temp1->next (which is null ) and therefore it will give segfault.
one simple logic is -> create two list even(containing only even element) and odd (only odd elemets) from the given list.
and then merge them (tail of odd with head of even).
i checked it using C++ Visualizer. logic is working. cant we handle this NULL issue?
add one more condition ,even->next!=NULL.
i think your code will not preserve relative ordering.
for example-> order of 2 ,4 6 in given list is 2 , 4, 6
then in output it should be same .
4
2 2 2 1
try ur code for this
for this. output isβ> 2, 1, 2, 2. odd should point to null in starting.
yeah .
try this one
4
1 1 1 1
giving only one 1.
what changes i should do?
Can we discuss this on call?
u need to handle the case where no even node is present
sorry , cant help u over call.
okay. Can you do the changes in this ide, i will take the reference: https://ide.codingblocks.com/s/268461
check this,
logic is exactly same as urs .
evenH stands for head of even node, evenT stands for Tail for even node.
similary for odd nodes.
One more thing, if we will implement taking two separate even and odd LL and then merge them, space complexity will be O(n). So is it fine to use while doing competitive coding? I am asking this in the reference of all the other questions too.
space complexity matters?
time complexity is preferred over space complexity.
for this probelm u can use same node instead of creating new node . (for o(1) space complexity.