Jump to content
Sign in to follow this  

Sorting Array using MAIN and Secondary index

Recommended Posts



This is my small contribution.

This code will first generate a 2 column array, and random some values. It will then sort the array using the 2nd column, and then sort some more using the 1st column. I have searched a lot and didnt found anything so i build mine!

TO DO: Use UBOUND(ARRAY) to find the array size

#include <array.au3>
;create Sample Array
Local $Array[100][3]
$Array[0][0] = "index"
For $i = 1 To 99
$Array[$i][1] = Int(Random() * 5) * 10
$Array[$i][2] = Int(Random() * 5) * 10
$Array[30][1] = 33
$Array[30][2] = 33
$Array[40][2] = 22
$Array[40][1] = 22
$Main_Index = 2
$Secondary_Index = 1
_ArraySort($Array, 0, 0, 0, $Main_Index)
$start = 1
$i = $start
If $Array[$i][$Main_Index] = $Array[$i + 1][$Main_Index] Then
   $i += 1
  Until $i = 99 Or $Array[$i][$Main_Index] <> $Array[$i + 1][$Main_Index]
  _ArraySort($Array, 1, $start, $i, $Secondary_Index);small sort secondary index
$start = $i + 1
Until $start >= 98 ;Array size -1

Hope it helps

Share this post

Link to post
Share on other sites

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

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.