I need to sort an array of strings alphabetically in c++ and I have no idea how to do this...
I would prefer to do this without pointers or qsort or std::sort
Thanks,
Dustin
I need to sort an array of strings alphabetically in c++ and I have no idea how to do this...
I would prefer to do this without pointers or qsort or std::sort
Thanks,
Dustin
you could try this:
void SelectionSort(apvector<apstring>&v){
n=v.length();
while(n>1){
//find largest element
for(iMax=0, i=1; i<n; i++)
if(v[i]>v[iMax])
iMax=i;
//swap
temp=v[n-1];
v[n-1]=v[iMax];
v[iMax]=temp;
}
}
convert the strings to all lower case or all upper case unless you feel A is different from a. Then use strcmp() to comare c_style strings, swapping the two strings if appropriate. If you are using STL style strings or apstrings or TStrings or CStrings then you can use a logical operator to do the comparison.