Sort the given doubly linked list using bubble sort.
Input : 5 4 3 2 1 Output : 1 2 3 4 5 Input : 2 1 3 5 4 Output :1 2 3 4 5
As we do in the bubble sort, here also we check elements of two adjacent node whether they are in ascending order or not, if not then we swap the element. We do this until every element get its original position.
In 1st pass the largest element get its original position and in 2nd pass 2nd largest element get its original position and in 3rd pass 3rd largest element get its original position and so on.
And finally whole list get sorted.
Note: If the list is already sorted then it will do only one pass.
Linked list before sorting 90 1 11 2 56 12 Linked list after sorting 1 2 11 12 56 90
- C Program for Bubble Sort on Linked List
- Sort the biotonic doubly linked list | Set-2
- Sort the biotonic doubly linked list
- Merge Sort for Doubly Linked List
- Insertion Sort for Doubly Linked List
- Sort a k sorted doubly linked list
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- Difference between Singly linked list and Doubly linked list
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Reverse a Doubly Linked List | Set-2
- Reverse a Doubly Linked List
- QuickSort on Doubly Linked List
- Reverse a Doubly linked list using recursion
- Implementation of Deque using doubly linked list
- Delete all the even nodes from a Doubly Linked List
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.