Segregate Even And Odd Nodes In A Linkedlist

easy
Given a singly linklist, 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 same as that in the original list.

Input Format

1->7->2->6->3->5->4->null

Output Format

2->6->4->1->7->3->5->null

Constraints

0 <= N <= 10^6

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
4
0
6
7
5
Output
0 6 7 5 
Previous
Mergesort Linkedlist
Next
Remove Nth Node From End Of Linkedlist

Related Questions