Update appNew update is available. Click here to update.

Quick Sort on Linked List

Contributed by
Deepanshu_1780
Last Updated: 23 Feb, 2023
Medium
yellow-spark
0/80
Avg time to solve 35 mins
Success Rate 65 %
Share
8 upvotes

Problem Statement

Suggest Edit

You are given a Singly Linked List of integers. Sort the Linked List using Quick Sort Algorithm.

Quick Sort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot such that the elements before the pivot are less than the pivot and all the elements greater than or equal to the pivot come after the pivot.

Detailed explanation ( Input/output format, Notes, Images )
Constraints :
1 <= T <= 10
1 <= L <= 10 ^ 2
- 10 ^ 9 <= DATA <= 10 ^ 9 and DATA != -1

Where 'T' is the number of test cases, 'L' is the number of nodes in the linked list and 'DATA' is the value of any node in the given linked list.

Time limit: 1 sec.
Sample Input 1:
3
1 -2 3 -1
9 9 -1
4 -1
Sample Output 1:
-2 1 3 -1
9 9 -1
4 -1
Explanation for Sample Input 1:
For every test case, the sorted list is printed, terminated by -1.
Sample Input 2:
2
1 1 1 -1
3 -3 -1
Sample Output 2:
1 1 1 -1
-3 3 -1
Reset Code
Full screen
Auto
copy-code
Console