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 email@example.com. 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
- Sort elements by frequency | Set 1
- Count Inversions in an array | Set 1 (Using Merge Sort)
- Merge Sort for Linked Lists
- Sort an array of 0s, 1s and 2s
- Find the Minimum length Unsorted Subarray, sorting which makes the complete array sorted
- Stability in sorting algorithms
- Which sorting algorithm makes minimum number of memory writes?
- Lower bound for comparison based sorting algorithms
- std::sort() in C++ STL
- Sort a nearly sorted (or K sorted) array
- Sort numbers stored on different machines
- Iterative Quick Sort
- Sort a linked list of 0s, 1s and 2s
- Pancake sorting
- A Pancake Sorting Problem