Alphabet sort
BlitzMax Forums/BlitzMax Beginners Area/Alphabet sort
| ||
Anyone have any tips of ideas on how to sort a list of strings into alphabetical order. At the moment, I'm doing it by comparing the ascii values of each bit of the string, and then quicksorting them into value order. It's sort of working, but it struggles when you put stuff like "aaaa", "aaa" in there and also stuff liked "plop 1", "plop a", "plop b". Surely there's a better way? :) |
| ||
Doesn't TList have a sort method? :P |
| ||
You could do If SomeString.ToLower() > OtherString.ToLower() Then... |
| ||
Or simply use SortList() :) |
| ||
The problem with SortList() is that it will sort based on ASCII value rather than alphabetical. Meaning that strings that are capitalized will appear before strings which are lowercase. Using quicksort with my version of compare will sort the strings by alphabet regardless of case. |
| ||
I'd override the compare method of a string wrapper custom type and use mystringtypelist.sort() |
| ||
Oh, Blitzmax has a sorting method? Anyone have any sample code? I'm not exactly tooled up on TLists. :) |
| ||
LOL theres loads of people throwing their rattles out of the pram about the compare method at the moment!! have a look at my site theres a list tutorial there |
| ||
arrays have sort too!Local cheese$[10] Local c:Int=0 cheese[c]="Wasn't";c:+1 cheese[c]="ENAY";c:+1 cheese[c]="the";c:+1 cheese[c]="one";c:+1 cheese[c]="who";c:+1 cheese[c]="likes";c:+1 cheese[c]="cheese?";c:+1 cheese.sort() DebugLog "case sensitive sorted:" For c=0 To 9 DebugLog cheese[c] Next End (run @ debugmode) |
| ||
Wow CS_TBL! I want your babies! |
| ||
Or simply use SortList() Problem is, it uses a bubblesort implementation (quadratic) where as a quicksort (n log n) is much faster. |