in this question we have to maintain the order of the number same or we have to do according to sorting example-2 3 6 1 1 5
anser1-3 1 1 5 2 6 or anser2 -1 1 3 5 2 6 what is the sequence??
Even after odd quess
We just have to rearrange the input linked list so that all even numbers are placed after the odd ones.
The answer of your test case is - 3 1 1 5 2 6
The relative order should be maintained.
if i want to consider the lowest element first then anser will be anser2 so how can i do this i have to use sorting also??
No you don’t have to use sorting or anything else. Just do one simple thing -
Traverse the linked list from the start. And whenever you encounter an even element, just push it to the end of the linked list.
ya i understood that part but if i want anser 2 which is according to sorted order the i have to do sorting also odd sorting + even sorting??
No you don’t have to perform sorting of any kind. You are not able to understand my point.
I will explain you with the help of an example -
Lets say the input linked list is - 2 3 6 1 1 5
We start from 2. It is even, so we push it to the end. And our intermediate linked list becomes - 3 6 1 1 5 2
Now we are at 3 and it is odd. So we just increment our pointer.
Now the element 6 is even. So we again push it to the end and our intermediate linked list becomes - 3 1 1 5 2 6
Then we move on to 1 which is odd and just increment. And like this we finally reach the last element of our original linked list which is 5. So we stop there and display the final linked list.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.