Please enter your email address or userHandle.
Given a Linked list of size N, the list is in alternating ascending and descending orders. Your task is to complete the function sort() that sorts the given linked list in non-decreasing order.
Output: 1 2 3 7 8 9
Explanation: After sorting the given
linked list, the list will be as
1-> 2-> 3-> 7-> 8-> 9.
Output: 13 21 50 80 99
The task is to complete the function sort() which should sort the linked list in non-decreasing order. The sorted linked list is printed by the driver's code.
Note: Complete the task in constanst auxilliary space.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
1 <= Number of nodes <= 100
0 <= Values of the linked list <= 103
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Login to access your submissions.
Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.