## sort a list in ascending order without [zl sort]

Oct 16 2013 | 1:11 pm
so here is what im trying to do. i want to understand what [zl sort] does. to do this i want to make a patch that does the same but without shortcuts :). now iv been racking my brain but i cant for the life of me work out what to do. All i need is a patch that will do the following conversion to any list of numbers:-
Original list :- 1 3 2 5 4 6 or 6 1 5 2 4 3 sorted list :- 1 2 3 4 5 6 -- 1 2 3 4 5 6
the way i need it to work is it takes the string from a [Message] box load it into a [coll] object then the string needs to be sorted into order and printed in the empty message box at the bottom of the process.
this should work for any set of numbers so it just needs to be in size order smallest to largest.
Original list :- 106 52 31 11 94 55 sorted list :- 11 31 52 55 94 106
i hope iv explained myself enough. i look forward to any help.
MiRAGE

• Oct 16 2013 | 1:28 pm
I'm pretty sure these will give you some ideas :)
• Oct 16 2013 | 2:12 pm
while these are comical videos . how can i impliment the algorithms in max without using jit.bsort or suchlike ? i understand the bubble sort algorythm so i will use that one but i just cant work out how to impliment it in max :/
• Oct 18 2013 | 5:16 am
This is all about working with lists. Familiarize yourself with the entire set of zl objects. Make use of simple storage objects such as f, i, zl reg, bag, etc. Make extensive use of the trigger object to direct and sequence events in your patch. Learn to store and edit list elements in indexible objects such as coll, multislider, table, etc. Simplify your goal into a series of sequential steps and implement it one piece at a time.
• Oct 18 2013 | 6:31 am
Can'tyou use Coll for that ? I know you can sort a list in alphabetical order but am not sure about sorting numbers.
• Oct 18 2013 | 1:08 pm
Yes, you can use coll for that [sort -1 -1] Quick example:
• Oct 18 2013 | 9:36 pm
i think the op wants to implement the algorithm from scratch as a learning exercise, not simply use a built in sort feature in max.
my pseudocode for this would be: put it all in a coll; compare the first two entries; swap if 2nd entry is lower than first; compare next two entries (ie 2nd & 3rd) etc etc
should be able to do this with one or two colls and /or zl reg objects, with uzi
• Oct 18 2013 | 10:00 pm
The OP created another thread asking about implementation of a bubble sort algorithm. I personally found coll to be more cumbersome (probably just my inexperience).
• Oct 18 2013 | 10:28 pm
sure i'd do it without coll too, but it has a text editor, so you can see how the algorithm works for each iteration, so it's a worthwhile from a diagnostic/prototyping /pedagogical perspective. it also preserves the original order if you don't renumber the indices, if that's necessary, and you can easily attach other data to it, like text strings so it's extensible. but this thread is probably dead anyway, as far as the op is concerned :O
• Mar 13 2016 | 7:33 pm
In SHORTY's example, why are the delays necessary?
I tried removing them and using triggers to control the order of events, but without them, it looks like coll isn't finished sorting yet when it dumps. Is there a way to know when coll is finished sorting? (I'd rather not use delays for this sort of thing.)
• Mar 13 2016 | 10:37 pm
Because the trigger puts out 10 bangs in less than 20 ms.
• Jan 18 2017 | 11:08 pm
This is what I came up with to break down the logic behind 'sort -1 -1':