Given a singly linked list, sort it using bubble sort by swapping nodes.
Input: 10->30->20->5 Output: 5->10->20->30 Input: 20->4->3 Output: 3->4->20
- Get the Linked List to be sorted
- Apply Bubble Sort to this linked list, in which, while comparing the two adjacent nodes, actual nodes are swapped instead of just swapping the data.
- Print the sorted list
Below is the implementation of the above approach:
Linked list before sorting 5 -> 1 -> 32 -> 10 -> 20 -> 78 -> Linked list after sorting 1 -> 5 -> 10 -> 20 -> 32 -> 78 ->
- Bubble Sort On Doubly Linked List
- C Program for Bubble Sort on Linked List
- Swap nodes in a linked list without swapping data
- Recursive selection sort for singly linked list | Swapping node links
- Reverse a Doubly Linked List | Set 4 (Swapping Data)
- Comparison among Bubble Sort, Selection Sort and Insertion Sort
- Splitting starting N nodes into new Circular Linked List while preserving the old nodes
- Append odd position nodes in reverse at the end of even positioned nodes in a Linked List
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Delete N nodes after M nodes of a linked list
- Linked List Sum of Nodes Between 0s
- Sum of all odd frequency nodes of the Linked List
- Find sum of even and odd nodes in a linked list
- Find the sum of last n nodes of the given Linked List
- Sum of the nodes of a Singly 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.