ID:786409

So I decided that rather than plug and play a library, I would try to create my own mini library for sorting associated lists. Here's my creation:

 ``` OrganizeNumbers(list/AS) //Associated List to sort by Associated Values if(!AS) world << "ERROR: No list." return world << "Organizing numbers..." var list/TempCount[] = list() i = 1 Comparer //Value to be compared to the list with h //Holder. Holds the index of the Comparer for reference later while(Count.len > 0) if(i > AS.len) TempCount[AS[h]] = AS[AS[h]] AS.Remove(AS[h]) i = 1 if(AS.len) Comparer = AS[AS[i]] h = i for(i,i<=AS.len,i++) var/b = AS[AS[i]] if(Comparer < b)break var/b for(b=1,b<=TempCount.len,b++) AS[TempCount[b]] = TempCount[TempCount[b]] world << "List reorganized!" ```

It works great, but I wondered if my peers might have more efficient ideas or concepts?
 #1 May 30 2012, 2:48 pm An associated value can be non-numeric, can't it? What happens if you put a mixed list into this? What about a list of strings? Atoms? Some sort of modality to determine how to sort would be awesome, too. For example, ascending/descending numeric, ascending/descending text etc.
 #2 May 30 2012, 2:53 pm Haha I see what you mean! This is definitely more suited for strictly numerical comparisons. Is it even possible to compare a number versus an object? As for different sorting options, I think that's a great idea!
 #3 May 30 2012, 2:57 pm In response to Michael3131 (#2) Michael3131 wrote: Is it even possible to compare a number versus an object? No, not really. You should probably add options for precedence. So we can choose if we want numbers, strings, or objects to be placed first.
 #4 May 31 2012, 2:12 pm In response to Michael3131 (#2) Michael3131 wrote: Is it even possible to compare a number versus an object? The problem isn't whether or not you can, you just don't want it to crash your proc if/when it tries.