Umm, well, If you have the data to be sorted in an array, wouldn't it be very much easier to use the qsort(3)-function?
In this case the code example would be:
#include <stdlib.h>
#include <stdio.h>
int my_cmp(const void *item1, const void *item2) {
return strcmp(*(const char **)item1, *(const char **)item2);
}
int main()
{
char *strings[] = {"hello", "world", "qsort", "rocks"};
int i;
qsort((void *)strings, 4, sizeof(char *), my_cmp);
for (i = 0; i < 4; i++) {
printf("%s\n", strings
);
}
return 0;
}
Or if you stored it in a vector<string> instead you could use the much easier code:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
vector<string> strings;
strings.push_back("hello"
;
strings.push_back("world"
;
strings.push_back("STL"
;
strings.push_back("rocks"
;
sort(strings.begin(), strings.end());
for (unsigned i = 0; i < strings.size(); i++) {
cerr << strings << endl;
}
}