# sorting 2d array using a different 2d array using the 2nd dimension

## Recommended Posts

I ned to sort an array. Heres what i mean

the fist dimension is infinite and the last array needs to never change

1st array:

\$a[1][1] = 0xFFFFFF

\$a[2][1] = 0xEEEEEE

\$a[3][1] = 0xDDDDDD

\$a[4][1] = 0xCCCCCC

\$a[5][0] = 4

\$a[5][1] = ""

2nd array:

\$a[1][1] = 0xEEEEEE

\$a[2][1] = 0xFFFFFF

\$a[3][1] = 0xDDDDDD

\$a[4][0] = 3

\$a[4][1] = ""

2nd array after sort:

\$a[1][1] = 0xFFFFFF

\$a[2][1] = 0xEEEEEE

\$a[3][1] = 0xDDDDDD

\$a[4][0] = 3

\$a[4][1] = ""

[size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N

##### Share on other sites

I ned to sort an array. Heres what i mean

the fist dimension is infinite and the last array needs to never change

1st array:

\$a[1][1] = 0xFFFFFF

\$a[2][1] = 0xEEEEEE

\$a[3][1] = 0xDDDDDD

\$a[4][1] = 0xCCCCCC

\$a[5][0] = 4

\$a[5][1] = ""

2nd array:

\$a[1][1] = 0xEEEEEE

\$a[2][1] = 0xFFFFFF

\$a[3][1] = 0xDDDDDD

\$a[4][0] = 3

\$a[4][1] = ""

2nd array after sort:

\$a[1][1] = 0xFFFFFF

\$a[2][1] = 0xEEEEEE

\$a[3][1] = 0xDDDDDD

\$a[4][0] = 3

\$a[4][1] = ""

How did the counts wind up in the last row vice the first ([0][0])? That's very non-standard.

At any rate, this only takes two For/Next loops, one nested inside the other. Loop through the first array, and on each value loop through the entire second array, copying matches to a temporary array declared the same size as the second. On each match, you will be deleting that row from the second array, which means you need to loop with "Step -1" through it. After all the matches have been copied and removed, the remaining rows can be copied, including the last (count).

Give it a try. If you get stuck, post what you tried and you'll get plenty of help.

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

## Create an account

Register a new account