473,396 Members | 1,864 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,396 software developers and data experts.

How to sort multi-dimensional array?

18
Hi there,
I need to sort multi-dimensional array by two columns. I.e. I have the following:

a b c
-----------
1 12 1
0 10 2
1 10 3
1 15 4
0 14 5

So the result should look like this:

a b c
-----------
1 15 4
1 12 1
1 10 3
0 14 5
0 10 2

As you can see I need to order it in descending order by column A first and then by column B so that column C should still be mapped appropriately.

When I had just 2 columns (B and C) it was pretty easy to do:

Hashtable HTPreferenceOrder = new Hashtable();
//next line is in loop
HTPreferenceOrder.Add(B,C);
//end loop
int count= HTPreferenceOrder .Count;
int[] B= new int[count];
int[] C= new int[count];
HTPreferenceOrder.Keys.CopyTo(B,0);
HTPreferenceOrder.Values.CopyTo(C, 0);
Array.Sort(B, C);
Array.Reverse(C);

That's it. I got column C in descending order like i wanted it to be. But now i had to add column A and sort by it first. Please help, need to do it ASAP.

Thanks in advance.
Aug 18 '07 #1
2 1497
kenobewan
4,871 Expert 4TB
Have you tried doing the same with column A?
Aug 19 '07 #2
Dimon
18
Have you tried doing the same with column A?
Do what with column A? I can't do it with column A because i need it to be sorted by column A and column B and so column C is still mapped appropriately.
Aug 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: WU FUHENG | last post by:
Today,I found a strange problem in python multi-thread programming.When I used function win32com.client.Dispatch('ADODB.Connection') in primary thread, it was OK. But when I called it in...
0
by: mikeswk | last post by:
Hi, all I'm using jsp to connect to mysql 3.23.44 max using connector 3.0.6 (default charset=latin1) I'm trying to put some multi-byte characters (for example big5) together with latin...
6
by: Andrew V. Romero | last post by:
First off, I am mostly familier with PHP but am trying to make a multi-step javascript program. For an example, I would like to run different sections of the script depending on how many times the...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
5
by: Dr. Ann Huxtable | last post by:
Hello All, I am reading a CSV (comma seperated value) file into a 2D array. I want to be able to sort multiple columns (ala Excel), so I know for starters, I cant be using the array, I need...
4
by: P Adhia | last post by:
Hello, If the explain shows that DB2 needs to sort the result of a cursor, does that always happen? i.e. if the resultset of the cursor is empty, does the sort have any overhead? It appears...
7
by: Nicolas | last post by:
Hello, Please excuse me if I am a little off-topic. I would like to know what graphical library is the best to use for a multiplatform (Windows, Mac Os, Linux) application. I know GTK, but it is...
18
by: xahlee | last post by:
Last year, i've posted a tutorial and commentary about Python and Perl's sort function. (http://xahlee.org/perl-python/sort_list.html) In that article, i discussed a technique known among...
4
by: jehugaleahsa | last post by:
Hello: I want to know the best way to sort a BindingList without needed to turn it into a DataTable. Of course, my BindingList is being used indirectly by a BindingSource. So, how do I sort a...
3
by: jim | last post by:
Each night, a scheduled task copies certain information from an MS Access db to a MySQL db that serves as a data warehouse. I would like to begin replicating multi-value fields from Access to...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.