Sorting

for ( int h = 0 ; h<j ; h++ )
{
for(int i=0; i<j; l++)
{

if(book1[i]>book2[l+1])
{
temp = counter[l];
counter[i] = counter[i+1];
counter[i+1] = temp;
temp_1= [i];
book1[i] = book2[i+1];
book1[i+1] = temp_1;


}
}

Will this sort a list of names?
Couldn't you try it out and see for yourself?
Potentially, but i think it should really go more like this:
1
2
3
4
5
6
for (int i = 0; i < numOfNames; i++) {
     for (int j = 1; j <= numOfNames; j++) {
          if (counter[j] < counter[j - 1])
               swap(counter[j], counter[j - 1]);
     }
}


This will sort an array of strings according to the total ascii value of each of the words. For example, the word 'dog' has a total ascii value of 100+111+103 (see http://ee.hawaii.edu/~tep/EE160/Book/chap4/subsection2.1.1.1.html for character values). If you want to sort the words by their first letter, then you need compare the first letter of the word(s).
Topic archived. No new replies allowed.