Hello!
I'm making a function that generates a random name (only once). The names are originally stored in a linked list (doubly circular)
1)I copy the names in an array of strings (in order to generate a random index each time, 2) look for the string( with the given index)in the linked list and if existing, will call a delete function to delete it, if not found it will be called again, after generating many strings, my program crashes.
here is the function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
string generate(Bloc*root){
string str;
k= rand();
if(k <= nbrElements){
str=savedArray[k];
for(Bloc*it = root->nxt; it!=root; it= it->nxt){
if(it->name==str)
return str;
}
}
else return genererKenfant(root);
}
|
in the main, here's what happens:
1) store the generated string in a variable
2) send this variable to a search function that returns the adress of the block contating this string
3)create another list and call the AddAfterRoot function(to save the variable generated in this list)
4) delete the block by passing it to my delete function
Please help!