Forums > MaxMSP

sort a list in ascending order without [zl sort]

October 16, 2013 | 6:11 am

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.

many thanks in advance,

MiRAGE


October 16, 2013 | 6:28 am

I’m pretty sure these will give you some ideas :)

http://www.youtube.com/user/AlgoRythmics/videos


October 16, 2013 | 7:12 am

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 :/


October 17, 2013 | 10:16 pm

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.


October 17, 2013 | 11:31 pm

Can’tyou use Coll for that ? I know you can sort a list in alphabetical order but am not sure about sorting numbers.


October 18, 2013 | 6:08 am

Yes, you can use coll for that [sort -1 -1] Quick example:

<code>

– Pasted Max Patch, click to expand. –

</code>


October 18, 2013 | 2: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


October 18, 2013 | 3: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).


October 18, 2013 | 3: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


Viewing 9 posts - 1 through 9 (of 9 total)