473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Sorting two dimensional array how to ?

I have the following two dimension array:

public double[,] mData = new double[259200,3];

now I need to sort the values based on the values of third index of the
second dimension, like

[0,0]= 11
[0,2]= 22
[0,3]= 444
[1,0]=1
[1,2]=33
[1,3]=11
[2,0]=333
[2,2]=44
[2,3]= 222

I need it to be after sorting using the third (index 2) of the second
dimension

[0,0]= 1
[0,2]= 33
[0,3]= 11
[1,0]=333
[1,2]=44
[1,3]=222
[2,0]=11
[2,2]=22
[2,3]= 444

Thanks in advance for you help


Nov 17 '05 #1
2 11136
Carlos <cp@swa.com> wrote:
I have the following two dimension array:

public double[,] mData = new double[259200,3];

now I need to sort the values based on the values of third index of the
second dimension, like


The way to do this is to use jagged arrays instead of rectangular ones.
Then you've got an array of arrays, and you can sort that in the same
way that you can sort any other single-dimensional array with
Array.Sort, providing an IComparer to compare elements (each element
will be an array, that you take the 3rd element of to use for
comparisons).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
Thanks Jon
I check the jagged array
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Carlos <cp@swa.com> wrote:
I have the following two dimension array:

public double[,] mData = new double[259200,3];

now I need to sort the values based on the values of third index of the
second dimension, like


The way to do this is to use jagged arrays instead of rectangular ones.
Then you've got an array of arrays, and you can sort that in the same
way that you can sort any other single-dimensional array with
Array.Sort, providing an IComparer to compare elements (each element
will be an array, that you take the 3rd element of to use for
comparisons).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: lawrence | last post by:
Is there an easy way to sort a 2 dimensional array alphabetically by the second field in each row? Also, when I use sort() on a two dimensional array, it seems to work a lot like...
4
by: Todd | last post by:
I'm new to c++ and was wondering how to sort a 2 dimensional array. I'm using a select sort for 1 dimensional arrays but it is not working for a 2 dimensional array. The 2 dimensional array are...
18
by: bsder | last post by:
Hi, Can anyone please tell me how to calculate the size of the following 4-dimensional array, and now to use qsort for sorting on this array? double sp = { 4.0, 5.0, 6.0 }; double spa = { {...
10
by: Roy Gourgi | last post by:
Hi, How would I sort an array? TIA Roy
0
by: Sick | last post by:
Hey, The Array.Sort function only applies to one-dimension arrays. Is there a solution for sorting a two-dimensional array, preferably *without* the usage of additional controls such as...
4
by: Balaskas Evaggelos | last post by:
Hi, does anyone know how i can sort a multi-dimensional array by a specific field ? for example i want to sort arr where n=2, but i need the data of every array to follow that order. ...
20
by: Acolyte | last post by:
Hey, I'm working on a project that involves sorting a two-dimensional array of integers using bubble sort. I've got it semi-working, my only issue is that it seems to be 'losing' values, I'm assuming...
5
by: JC | last post by:
Hi all, I have scoured the internet for articles on sorting multi-dimensional arrays of generic types e.g. T using the IComparer<Tinterface and have run into a real roadblack. There does not...
1
by: Totti | last post by:
Hi everyone, I am a newbie to javascript learning it for 2 months now, i am trying to make a sorter who will read english words from the one textbox or datafile and store them in a 2 dimensional...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.