c++ - Arranging an array of strings (or even a *ptr) alphabetically -


so i've read 5 or 6 posts on how re-arrange arrays, alphabetically numerically, , read chapter. came with,

void selectionsort (string array[], int size) { int startscan, minindex; string minvalue; for(startscan = 0; startscan<(size-1); startscan++) {     minindex = startscan;     minvalue = array[startscan];     string temp;     for(int index = startscan+1; index<size; index++)     if(array[index] <minvalue)     {         minvalue = array[index];         minindex = index;     } } array[minindex] = array[startscan]; array[startscan] = minvalue; system("pause"); } 

obviously, doesn't work. hollers @ me needing break when run it. presume work, int or of number types. heck, run if had set ascii values char type. actual assignment string, , can't figure out. thought trying snip out first letter , convert char alphabetize way, of strings have have same last name different first name, wouldn't work either.

what need fix allow sort alphabetize array?

update updated had changed in code after reading comments , re-looking on book. no longer error when running code, still doesn't sort!

so reason choose not use std, ( have both swap , sort)

i note attention to:

  temp = array[count];     array[count]=array[(count+1)]; <-- when count size -1 going commit overflow array     array[(count+1)] = temp; 

you need make sure indexing not go on array bounds..:

for(int count = 0; count<size -1 ; count++) 

(btw take @ std::swap, might nicer use)


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -