sort a list in ascending order without [zl sort]

Oct 16, 2013 at 6:11am

sort a list in ascending order without [zl sort]

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

#268201
Oct 16, 2013 at 6:28am

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

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

#268202
Oct 16, 2013 at 7:12am

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

#268208
Oct 17, 2013 at 10:16pm

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.

#268349
Oct 17, 2013 at 11:31pm

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

#268350
Oct 18, 2013 at 6:08am

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

<code>

– Pasted Max Patch, click to expand. –

</code>

#268369
Oct 18, 2013 at 2:36pm

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

#268417
Oct 18, 2013 at 3:00pm

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).

#268420
Oct 18, 2013 at 3:28pm

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

#268422

You must be logged in to reply to this topic.