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 ->
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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
- Append odd position nodes in reverse at the end of even positioned nodes in a Linked List
- Splitting starting N nodes into new Circular Linked List while preserving the old nodes
- 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
- Sort a linked list of 0s, 1s and 2s
- Sum of the alternate nodes of linked list
- Sum of all odd frequency nodes of the Linked List
- Linked List Product of Nodes Between 0s
- Sum of all distinct nodes in a linked list
- Find sum of even and odd nodes in a linked list
- Sum and Product of all the nodes which are less than K in the linked list
- Sum of the nodes of a Circular 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.
Improved By : SHUBHAMSINGH10