Run time error in even after odd

approach I used is to maintain 2 linked list one or odd and one for even and the join both but it gives runtime error

I also tried another approach to traverse through the array and if we encounter odd then link it with first node that is even

It will be nice if you could help me solve the error of either of these approaches(first method preferred)

hello @prerna_gupta31
it is giving runtime error becuase u missed to handle two cases.

a) no odd element present

b) no even element present
image
these lines will give error.
also the starting two while loop is not required.

check this ->