I'm just trying to figure out if there is any way i can switch 2 string of characters like numbers with swap function. Somehow, i'm getting application error when trying to sort the characters in alphabetical oder with this:
Am i doing it right or is there anyway i can sort the characters in alphabetical order
//push some char into the vector array
for(int j=1; j<Name.size(); j++)
for(int i=0; i<Name.size()-1; i++)
if( strcmp(Name[i], Name[k]) > 0)
char like int is represented in binary just like everything else. To make it more obvious, characters are mapped to the keyboard numerically. I'm certain any comparison sort algorithm will be able to sort characters like it does numbers. Just make sure that your functions accept pointer to char, and that should solve most your problem.
OK, you used one data type which takes care of itself, and then use another where you have to do all the work yourself.
Why not use vector<string> instead, then at least you don't have to worry about all the string allocation problems.
Also, if you don't need to write your own sort function, use a standard one
This should give you the ideas for sorting a vector<string>
Cool, i found it pretty much like this:
//push some into the vector
//the job is done