# Qsort Challenge

 07 July 2013 #16 DaveWortley   portfolio David Wortley Technical Director London, United Kingdom   Join Date: Dec 2004 Posts: 1,932 100 1000 10000 Yeah I'm not going to try 100000 OK sortCorrect() sortIncorrect() correct iterations:399 time:1 memory:3392L #(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...) incorrect iterations:1165 time:3 memory:38096L #(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...) OK sortCorrect() sortIncorrect() correct iterations:3332 time:10 memory:159016L #(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...) incorrect iterations:86508 time:157 memory:4818376L #(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...) OK sortCorrect() sortIncorrect() correct iterations:36699 time:74 memory:2023344L #(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...) incorrect iterations:8388633 time:16438 memory:23001380L #(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...) So by having my function as... `````` Case of ( ((v1[2]) == (v2[2]) and (v1[1] < v2[1])) : -1 ((v1[2]) == (v2[2]) and (v1[1] > v2[1])) : 1 ((v1[2]) < (v2[2])) : -1 ((v1[2]) > (v2[2])) : 1 default: 0 )`````` I Should be ok? __________________ Maxscript Made Easy... http://davewortley.wordpress.com/ share quote
 07 July 2013 #17 PolyTools3D Expert   portfolio Jorge Rodríguez Argentina   Join Date: Jun 2013 Posts: 1,257 Originally Posted by denisT: this is the base c# sort function (sort by first and by next) : `````` public static object[][] Sort(object[][] array) { Array.Sort(array, delegate(object[] x, object[] y) { int result = (x[0] as IComparable).CompareTo(y[0]); return (result != 0) ? result : (x[1] as IComparable).CompareTo(y[1]); }); return array; } `````` array of several types (integer, float, string) max automatically converts to object[] Thank you Denis! And for Point2/Point3 they should be converted to array first? #( #([1,1,1],[2,2,2],[3,3,3]), #([4,4,4],[5,5,5],[6,6,6]) ) #( #(#(1,1,1),#(2,2,2),#(3,3,3)), #(#(4,4,4),#(5,5,5),#(6,6,6)) ) __________________ Jorge Rodríguez PolyTools3D share quote
 07 July 2013 #18 denisT MAX Doctor   portfolio Denis Trofimov CA, USA   Join Date: Jul 2009 Posts: 9,948 Originally Posted by PolyTools3D: Thank you Denis! And for Point2/Point3 they should be converted to array first? #( #([1,1,1],[2,2,2],[3,3,3]), #([4,4,4],[5,5,5],[6,6,6]) ) #( #(#(1,1,1),#(2,2,2),#(3,3,3)), #(#(4,4,4),#(5,5,5),#(6,6,6)) ) true... only three base mxs types max aromatically converts to .net array (object)... also arrays of .net objects (classes) share quote
 07 July 2013 #19 denisT MAX Doctor   portfolio Denis Trofimov CA, USA   Join Date: Jul 2009 Posts: 9,948 Originally Posted by DaveWortley: So by having my function as... `````` Case of ( ((v1[2]) == (v2[2]) and (v1[1] < v2[1])) : -1 ((v1[2]) == (v2[2]) and (v1[1] > v2[1])) : 1 ((v1[2]) < (v2[2])) : -1 ((v1[2]) > (v2[2])) : 1 default: 0 ) `````` I Should be ok? that's OK. but if you would count the worse case you see that it needs make 6 comparisons. why? if you can do the same for only 4? `````` fn sortByIndex v1 v2 = if (v1[2] < v2[2]) then -1 else if (v1[2] > v2[2]) then 1 else if (v1[1] < v2[1]) then -1 else if (v1[1] > v2[1]) then 1 else 0`````` share quote
 07 July 2013 #20 CGTalk Moderation Expert   Join Date: Sep 2003 Posts: 1,066,473 Thread automatically closed This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum. share quote

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.