# Sorting Strings using Bubble Sort

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:

 `#include ` `using` `namespace` `std; ` `#define MAX 100 ` ` `  `void` `sortStrings(``char` `arr[][MAX], ``int` `n) ` `{ ` `    ``char` `temp[MAX]; ` ` `  `    ``// Sorting strings using bubble sort ` `    ``for` `(``int` `j=0; j 0) ` `            ``{ ` `                ``strcpy``(temp, arr[j]); ` `                ``strcpy``(arr[j], arr[i]); ` `                ``strcpy``(arr[i], temp); ` `            ``} ` `        ``} ` `    ``} ` `} ` ` `  `int` `main() ` `{ ` `    ``char` `arr[][MAX] = {``"GeeksforGeeks"``,``"Quiz"``,``"Practice"``,``"Gblogs"``,``"Coding"``}; ` `    ``int` `n = ``sizeof``(arr)/``sizeof``(arr); ` ` `  `    ``sortStrings(arr, n); ` ` `  `    ``printf``(``"Strings in sorted order are : "``); ` `    ``for` `(``int` `i=0; i

Output:

```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```

Sorting Sorting