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,
I’m pretty sure these will give you some ideas :)
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 :/
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.
Can’tyou use Coll for that ? I know you can sort a list in alphabetical order but am not sure about sorting numbers.
Yes, you can use coll for that [sort -1 -1] Quick example:
----------begin_max5_patcher---------- 1027.3ocyX0saaBCF8ZxSgEZWlEgMFSX2sq1CvtbZpxA7Z8DXh.mttVs284e fjzUnyKA6UoVPXr+x463y2O3mVEEuq8AVeL3Cfu.hhdZUTjYH8.QCOGE2Pen rl1alVbYaSCSHiWaemj8fzLNZC3yscR.W.n8kLQEWbKnsqh0AnhJP6A49CGW UMWvJaOHLKEMLHuxXn1ce+8H73L+VqPJnMLyq9XGmVe7Mc2tSOZxljylaO+Q ybgmFVbngKpYRC9gCCtui0qbCpj2JtoiUJsb.DkpVGHKWeMY3B3qmrjxOFM0 n82Skk2o71yLCBmrAkoriwZvLikPEZSoWyuVsReY8UR4vMfOwDrNpjo7W.ql omFnl2KAxVfjotGOA4l5ax0YdBigZlAmYnIBwba6ERS6NHkshobXT7EHExy2 jq1BygNHEFMkcH4O2yr1HdGUba7wEMkRQwk4GUJnjwqWDCHX+P4uuPmnjDfx ZFsaJtA5fX3h25QywKwqUxZCjbgbfEEZdoHwS5ijKQe.wHSLNxlxvaJDHY32 IOYAjHyRBvhX22WuBuARLdSJlr.dSCqumdK6EJ9pCM6mxG29OJ1SmVribpHR pMs1kJLbiFywlDn15LEKadiJVM3Trw47X9xjz.4KwEzjuHc6UkuXtro2o10u aFhgrrDybBLUJAcdQbRg2TXi4dwHiJNCcUb4bApPL.lq3RUVTUSS.TF.Q.oH PdBnHcJBFGlHXXtU.4wHXa6EXh4m.AQWUD7b7autk72CU+MEYlFDxDgrp0Ta +c9gMGJRllZnSRfyGhdilObr0gBxBjObNM16ff2Mo7JILwpYEV4EL06ICQ3s 9qbKWxlpC8Be1f9URGH7BTaX1VRyCRGo3jgBcYd7KvdkdFH+Wxc3Dk.sed9U t+NCmb3QN.NEgf8Igj9p5j0mty0GNkCbTtoSALwGTTGUT01n7vono+O0bbkV fIFdgf8RIGU6g5tESFZXT07nsQRUmiS11X1xVIZIygBG+r9BeTSorstFnaBb p5y9rvB90N4mi+6BAkVXOcPX1lrQozvp5o2yptQ4KpEcCUJ63pZI1iyN5HOE EyZ1wLtchY.CyNxuFaYNO5+3TvMHRO9yI891Ccki9x3gKBNAoJVujKL8nb1j xd1btiWUwDmeznU7d5t5y.4K18cENPWfitw+.gGcIu+NdPuw3m7vgmbWvSQv vSlCvQelwgR9.c.OEgENv+1tU3DOtDb8GQfdEOEtHl2FN73BbHgCNacAOgCN DWfC9YJduhmz2VzSxaJ33TnU3B0IN10SXjNtTDEGtpDNflvk0A6RMhKDM1tm o62eOqqevjFfn93ju21oejr17HWXezXw3N187w4uck1Z+Z0uAivk2aA -----------end_max5_patcher-----------
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)
should be able to do this with one or two colls and /or zl reg objects, with uzi
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).
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