1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
void pRadix_sort2(char *database)
{
vector <char*> keys;
int db_length = strlen(database);
//after his for loop, the keys vector will contain pointers to the beginning of each key
for(int i = 0 ; i < db_length ; i+=48)
{
keys.push_back(database + i);
}
//we sort the keys array starting from the end of the keys
for(int i = KEY_LENGTH - 1; i >=0 ; i--)
pCounting_sort2(keys,i);
char* temp_db = new char[strlen(database)];
*temp_db = '\0';//sinon temp_db contient des trucs bizarres avant...
//iterate on the keys vector and append the 48 chars following the pointer to temp_db
for(std::vector<char*>::iterator pKey = keys.begin(); pKey != keys.end(); ++pKey)
{
strncat(temp_db, *pKey, 48);
}
/*c'est ici que je dois faire en sorte que ce vers quoi pointe database soit modifé.
*/
//database = strdup(temp_db); -> database pointe vers l'espace alloué par strdup... Du coup c'est pas ce qu'il faut.
//strncat(database,temp_db,48);
//strncpy(database,temp_db,1); rien que copier un char ça marche pas...
//strncpy(database,temp_db,strlen(temp_db)); non plus du coup...
print_database(database);
//delete [] temp_db; <-- tjs pas résolu ce problème non plus
} |