Given a LinkedList of integers. Modify the LinkedList in such a way that in Modified LinkedList all the even numbers appear before all the odd numbers in LinkedList.
Example 1:
Input: 1→2→3→4→5→6→Null
Output: 2→4→6→1→3→5→Null
Explanation :
Odd Nodes in LinkedList are 1,3,5 and
Even Nodes in LinkedList are 2,4,6
In Modified LinkedList all even Nodes comes before
all Odd Nodes. So Modified LinkedList looks like
2→4→6→1→3→5→Null. Order of even and odd Nodes is
maintained in modified LinkedList.
Example 2:
Input: 1→3→5→Null
Output: 1→3→5→Null
Explantion: As there are no Even Nodes in LinkedList,
The Modified LinkedList is same as Original LinkedList.
Example 3:
Input: 2→4→6→8→Null
Output: 2→4→6→8→Null
Explanation: As there are no Odd Nodes in LinkedList,
The Modified LinkedList is same as Original LinkedList.
Given a LinkedList of integers. Modify the LinkedList in such a way that in Modified LinkedList all the even numbers appear before all the odd numbers in LinkedList.
Example 1: Input: 1→2→3→4→5→6→Null Output: 2→4→6→1→3→5→Null Explanation : Odd Nodes in LinkedList are 1,3,5 and Even Nodes in LinkedList are 2,4,6 In Modified LinkedList all even Nodes comes before all Odd Nodes. So Modified LinkedList looks like 2→4→6→1→3→5→Null. Order of even and odd Nodes is maintained in modified LinkedList.
Example 2: Input: 1→3→5→Null Output: 1→3→5→Null Explantion: As there are no Even Nodes in LinkedList, The Modified LinkedList is same as Original LinkedList.
Example 3: Input: 2→4→6→8→Null Output: 2→4→6→8→Null Explanation: As there are no Odd Nodes in LinkedList, The Modified LinkedList is same as Original LinkedList.