473,408 Members | 1,858 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,408 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 11138
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: 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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.