Sorting an Array

M

MFRASER

Does anyone have a sample or know how to sort a two dimensional array? I
want the first dimension ordered by the second dimension.

Meaning

Array
1,100
1,299
1,-100
2,200
2,400
3,599
3,-101

sorted should result in
3,-101
3,599
1,-100
1,100
1,299
2,200
2,400
 
V

Vanessa

The sort below will do what you want
change the constructor to pass in array number two
and add a line of code where I have indicated.


using System;
using System.Collections;

namespace Sort
{
public class Sort
{
public static int[ ] integers(int [ ] arg1)
{
int I2 = arg1.Length, I3 = I2;
int temp1;
while ((I2 = I2 / 2) != 0)
{
int I4 = I3 - I2, I5 = 0;
do
{
int I6 = I5;
do
{
int I7 = I6 + I2;
if (arg1[I6] > arg1[I7])
break;
// tyou have to add a swap line for the other array here
temp1 = arg1[I6];arg1[I6]=arg1[I7];arg1[I7]=temp1;
I6 = I6 - I2;
}
while (I6 > 1);
I5 = I5 + 1;
}
while (I5 < I4);
}
return arg1;
}
}
}
 
G

Guest

All managed arrays inherit from System.Array. This class has quite a few static sort functions, there's a few examples in the documentation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top