/* Program to illustrate sorting an array of strings */ #include #include using namespace std; const int SIZE = 5; int main() { string str[SIZE]; string tempstr; str[0] = "Jones"; str[1] = "Harrow"; str[2] = "Tenenbaum"; str[3] = "Arnow"; str[4] = "Raphan"; //print the original array cout << "Original Array" << endl; for (int i = 0; i < SIZE; i++) cout << str[i] << endl; // sort the array for (int pos = 0; pos < SIZE-1; pos++) for (int cand = pos+1; cand < SIZE; cand++) if (str[cand] < str[pos]) { tempstr = str[cand]; str[cand] = str[pos]; str[pos] = tempstr; } //print the sorted array cout << endl << "Sorted Array" << endl; for (int i = 0; i < SIZE; i++) cout << str[i] << endl; // system("pause"); //un-comment when using DevC++ return 0; }