Given an array of strings arr. Sort given strings using Bubble Sort and display the sorted array.
In Bubble Sort, the two successive strings arr[i] and arr[i+1] are exchanged whenever arr[i]> arr[i+1]. The larger values sink to the bottom and hence called sinking sort. At the end of each pass, smaller values gradually “bubble” their way upward to the top and hence called bubble sort.
After all the passes, we get all the strings in sorted order. Complexity of the above algorithm will be O(N2).
Let us look at the code snippet:
Strings in sorted order are : String 1 is Coding String 2 is Gblogs String 3 is GeeksforGeeks String 4 is Practice String 5 is Quiz
This article is contributed by Rahul Agrawal. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
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
- Sorting Algorithms Visualization : Bubble Sort
- Bubble sort using two Stacks
- C program for Time Complexity plot of Bubble, Insertion and Selection Sort using Gnuplot
- Recursive Bubble Sort
- Bubble Sort
- C Program for Bubble Sort on Linked List
- 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
- Bubble Sort On Doubly Linked List
- Bubble Sort for Linked List by Swapping nodes
- Sorting objects using In-Place sorting algorithm
- Know Your Sorting Algorithm | Set 1 (Sorting Weapons used by Programming Languages)
- Know Your Sorting Algorithm | Set 2 (Introsort- C++’s Sorting Weapon)
- Program to sort an array of strings using Selection Sort
- C++ program for Sorting Dates using Selection Sort