Computer Science Canada Selective Sorting |
Author: | a22asin [ Sun Dec 01, 2013 4:17 pm ] | ||
Post subject: | Selective Sorting | ||
Hi, so im trying to use selective sorting to sort an array of strings alphabetically (case -insensitive), where each string is one word. I got this codes from my textbook and i modified it to work with strings. But the array does not sort properly. It seems like it diesnt ignore the cases and it doesnt sort the words properly. ie.When i print array[0] through array [3] it will do: Ambro Aaron Aach aba instead of aba Aach Aaron Ambro
I have a feeling that i have modified the code wrong, but cant seem to find where. |
Author: | DemonWasp [ Sun Dec 01, 2013 5:18 pm ] |
Post subject: | RE:Selective Sorting |
The only problem I see is that your 'minValue' isn't necessarily lower-case. Remember that the .toLowerCase() method generates and returns a new string containing the lower-case value, rather than changing the existing value of the string. |
Author: | Zren [ Sun Dec 01, 2013 5:41 pm ] | ||
Post subject: | RE:Selective Sorting | ||
Quote: aba Aach Aaron Ambro That's not alphabetical either... When using compareTo between strings. If you want to sort by case-insentivity, you need both strings that you are comparing to be converted to the same case.
Edit: (╯?□?)╯︵ ┻━┻) |
Author: | a22asin [ Sun Dec 01, 2013 5:49 pm ] |
Post subject: | RE:Selective Sorting |
oh, i see what i did wrong, i forgot to change minValue to lowercase as well. Thanks.It worded. |