I am trying to sort an array of strings, but it\'s not sorting anything.... what am I doing wrong?
string namesS[MAX_NAMES];
int compare (const void * a, co
algorithm sort in CPP has the same complexity as qsort:
#include
#include
#include
#include
using namespace std;
bool compare(string a, string b){
cout << "compare(" << a << "," << b << ")" << endl;
return (a.compare(b) < 0);
}
int main () {
string mystrs[] = {"www","ggg","bbb","ssss","aaa"};
vector myvector (mystrs, mystrs + 5);
vector::iterator it;
sort (myvector.begin(), myvector.end(), compare);
cout << "vector contains:";
for (it=myvector.begin(); it!=myvector.end(); ++it)
cout << " " << *it;
cout << endl;
return 0;
}