I tried to learn the qsort function of the c-library stdlib
. This is provided even in c++
. But i dont understand how to use them for sorting
Works for me:
#include
#include
using namespace std;
#include
int compare_str( const void *a, const void *b){
string* obj = (string*)a;
string* obj1 = (string*)b;
return obj->compare(*obj1);
}
int main(){
string obj[4] = {"fine", "ppoq", "tri", "get"};
qsort(obj, 4, sizeof(string), compare_str);
for( int i=0; i<4; i++)
cout<