How can I sort strings in multiple languages?

Is it possible to use the bubble sort algorithm to sort strings?

  • Answer:

    Bubble sort will be able to sort the items lexicographically, if you first assign the strings a relative value. The way strcmp in the C library does this is by returning the difference of the first different characters between the strings. For instance, if you call strcmp("Hello", "Highway"), strcmp will return 'e'-'i'. The ascii value of e on a unix system is 101 and the ascii value of i is 105, so it is returning the value 101-105 = -4 which will tell you that "Hello" is lexicographically smaller than "Highway". Doing this, you should be able to use any algorithm you want to sort the strings.

wiki.answers.com Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.