sort a list in ascending order without [zl sort]

mirage's icon

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

FRid's icon

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

mirage's icon

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

metamax's icon

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.

Stephane Morisse's icon

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

spectro's icon
Max Patch
Copy patch and select New From Clipboard in Max.

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

Floating Point's icon

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

metamax's icon

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

Floating Point's icon

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

mattgilbertnet's icon

In SHORTY's example, why are the delays necessary?

Max Patch
Copy patch and select New From Clipboard in Max.

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

Rick's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Because the trigger puts out 10 bangs in less than 20 ms.

Karan Gour's icon

This is what I came up with to break down the logic behind 'sort -1 -1':

Sorting-Algo1.maxpat
Max Patch