Given a link list, modify the list such that all the even numbers appear before all the odd numbers in the modified list. The order of appearance of numbers within each segregation should be the same as that in the original list.
NOTE: Don't create a new linked list, instead rearrange the provided one.
Example 1
Input: Linked List: 1 -> 3 -> 5 -> 7 -> 2 -> 4 -> 6 -> 8
Output: 2 -> 4 -> 6 -> 8 -> 1 -> 3 -> 5 -> 7
Explanation: Even numbers (2, 4, 6, 8) appear first, followed by odd numbers (1, 3, 5, 7).
Example 2
Input: Linked List: 10 -> 21 -> 32 -> 43 -> 54 -> 65
Output: 10 -> 32 -> 54 -> 21 -> 43 -> 65
Explanation: Even numbers (10, 32, 54) appear first, followed by odd numbers (21, 43, 65).
Sign in to write, run, and submit your solution against the full test suite.