Problem of the day
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of each test case contains 'N'(number of nodes in the linked list) space-separated integers representing the value of each node. -1 at the end denotes NULL pointer.
For example :
The input 0 1 2 -1 denotes a linked list containing 3 nodes represented as:
For each test case, in a separate line, print the final sorted linked list.
You don’t have to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 100000
0 <= data <= 2
where ‘T’ is the total number of test cases, 'N' is the total number of nodes in the linked list and ‘data’ is the value of any node of the linked list.
2
0 1 1 2 2 1 1 1 0 1 -1
2 2 2 1 0 -1
0 0 1 1 1 1 1 1 2 2
0 1 2 2 2
For the first test case :
The given linked list is :
0 -> 1 -> 1 -> 2 -> 2 -> 1 -> 1 -> 1 -> 0 -> 1 -> null
Therefore after sorting the list will become :
0 -> 0 -> 1 -> 1 -> 1 -> 1 -> 1 -> 1 -> 2 -> 2 -> null
For the second test case :
The given linked list is :
2 -> 2 -> 2 -> 1 -> 0 -> null
Therefore after sorting the list will become-
0 -> 1 -> 2 -> 2 -> 2 -> null
3
0 0 0 -1
0 1 1 2 2 -1
2 2 2 2 2 0 -1
0 0 0
0 1 1 2 2
0 2 2 2 2 2