Quick Sort doubly linked list C++
Ngày đăng:
15/12/2021
Trả lời:
0
Lượt xem:
72
Q. Program to sort the elements of the doubly linked list.ExplanationIn this program, we will create a doubly linked list and sort nodes of the list in ascending order. Sorted List: To accomplish this, we maintain two pointers: current and index. Initially, current point to head node and index will point to node next to current. Traverse through the list till current points to null, by comparing current's data with index's data. If the current's data is greater than the index's data, then swap data between them. In above example, current will initially point to 7, and the index will point to 1. Since, 7 is greater than 1, swap the data. Continue this process till the entire list is sorted in ascending order. Algorithm
SolutionPythonOutput: Original list:
7 1 4 5 2
Sorted list:
1 2 4 5 7
COutput: Original list:
7 1 4 5 2
Sorted list:
1 2 4 5 7
JAVAOutput: Original list:
7 1 4 5 2
Sorted list:
1 2 4 5 7
C#Output: Original list:
7 1 4 5 2
Sorted list:
1 2 4 5 7
PHPOutput: Original list:
7 1 4 5 2
Sorted list:
1 2 4 5 7
|