I am a C++ beginner. I want to understand how is this function operating on a string to sort it?
int SA_cmp(const void *a, const void *b) { return strcmp(S + *(int*)a, S + *(int*)b); }
any pointer will help?
I am a C++ beginner. I want to understand how is this function operating on a string to sort it?
int SA_cmp(const void *a, const void *b) { return strcmp(S + *(int*)a, S + *(int*)b); }
any pointer will help?
 
    
     
    
    That's a C comparison function, not a (C++) sorting function.  A sort function (probably qsort, given the const void* arguments) would call it a number of times (passing it pointers to what are apparently indices into a buffer containing a number of null-terminated strings) in order to sort those indices (and, indirectly, the substrings they indicate).
 
    
    This will not sort a string.
This is a method that helps comparing strings and is used by sorthing methods as a helper method.
It will return a negative number if string a is lexicographically smaller than string b, 0 if they are equal, or a positive number if b is greater than a.
