Jump to content

Sort 2d Array fast


Recommended Posts

  • Moderators

Define "quick way"? Quicker than _ArraySort?

_ArraySort($test, Default, Default, Default, 2)

 

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I think _ArraySort sorts in alpha-numeric order - That may be why your array with 1000 entries didn't appear to be sorted.

After running this:

#include <Array.au3>

Global $g_eaNames[4] = [ 'Jax', 'Jade', 'Jaquie', 'Sonya' ]
Global $g_aArray[0][3]

For $i = 1 To 1000 Step 1
    Local $sName = $g_eaNames[Random(0, (UBound($g_eaNames) - 1), 1)]
    Local $iInteger1 = Random(1, 100, 1)
    Local $iInteger2 = Random(1, 1000, 1)
    _ArrayAdd($g_aArray, $sName & Chr(124) & _
                         $iInteger1 & Chr(124) & _
                         $iInteger2)
Next

_ArraySort($g_aArray, 0, Default, Default, 2)
_ArrayDisplay($g_aArray)

The Output was:

image.png.375d1d92a63da408bda22019674c5a69.png

Notice how 1000 is before 102.

Link to comment
Share on other sites

  • Moderators

See this post for actually adding elements as numbers, to avoid the sorting issue above:
 

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...