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 ->
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Comparison among Bubble Sort, Selection Sort and Insertion Sort
- C Program for Bubble Sort on Linked List
- Bubble Sort On Doubly Linked List
- Recursive selection sort for singly linked list | Swapping node links
- Swap nodes in a linked list without swapping data
- Bubble Sort
- Sorting Strings using Bubble Sort
- C Program for Bubble Sort
- C++ Program for Bubble Sort
- Java Program for Bubble Sort
- Python Program for Bubble Sort
- C++ Program for Recursive Bubble Sort
- Java Program for Recursive Bubble Sort
- Sorting Algorithms Visualization : Bubble Sort
- C program for Time Complexity plot of Bubble, Insertion and Selection Sort using Gnuplot
- Visualizing Bubble sort using Python
- Recursive Bubble Sort
- Bubble sort using two Stacks
- Generate Linked List consisting of maximum difference of squares of pairs of nodes from given Linked List
- Reverse a Doubly Linked List | Set 4 (Swapping Data)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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