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

arrange arrays in increasing order

I have array of arrays. I need to arrange them in an increased order of
their element 0

Here is what i want.
dim InputArray()() = {{2,0,0},{1,0,0},{6,0,0},{3,0,0}}

and this is the output
outputArray()() = {{1,0,0},{2,0,0},{3,0,0},{6,0,0}}

Has any body got any idea how to it.

TIA
nafri
Nov 21 '05 #1
4 1845
"nafri" <sp****@spam.net> schrieb:
I have array of arrays. I need to arrange them in an increased order of
their element 0

Here is what i want.
dim InputArray()() = {{2,0,0},{1,0,0},{6,0,0},{3,0,0}}

and this is the output
outputArray()() = {{1,0,0},{2,0,0},{3,0,0},{6,0,0}}

Has any body got any idea how to it.


Untested (written from scratch):

\\\
Imports System.Collections
..
..
..
Dim InputArray()() As Integer = _
New Integer()() { _
New Integer() {2, 0, 0}, _
New Integer() {1, 0, 0}, _
New Integer() {6, 0, 0}, _
New Integer() {3, 0, 0} _
}
Array.Sort(InputArray, New FooComparer)
..
..
..
Public Class FooComparer
Implements IComparer

Public Function Compare( _
ByVal x As Object, _
ByVal y As Object _
) As Integer Implements IComparer.Compare
Dim xx As Integer() = DirectCast(x, Integer())
Dim yy As Integer() = DirectCast(x, Integer())
Return yy(0) - xx(0)
End Function
End Class
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2
thanks, it works well, but arranges them in decreasing order. Although i can
reverse and get it what i want, but is their anything that i can do in the
compare function to make it arrange in decreasing order.

nafri

"Herfried K. Wagner [MVP]" wrote:
"nafri" <sp****@spam.net> schrieb:
I have array of arrays. I need to arrange them in an increased order of
their element 0

Here is what i want.
dim InputArray()() = {{2,0,0},{1,0,0},{6,0,0},{3,0,0}}

and this is the output
outputArray()() = {{1,0,0},{2,0,0},{3,0,0},{6,0,0}}

Has any body got any idea how to it.


Untested (written from scratch):

\\\
Imports System.Collections
..
..
..
Dim InputArray()() As Integer = _
New Integer()() { _
New Integer() {2, 0, 0}, _
New Integer() {1, 0, 0}, _
New Integer() {6, 0, 0}, _
New Integer() {3, 0, 0} _
}
Array.Sort(InputArray, New FooComparer)
..
..
..
Public Class FooComparer
Implements IComparer

Public Function Compare( _
ByVal x As Object, _
ByVal y As Object _
) As Integer Implements IComparer.Compare
Dim xx As Integer() = DirectCast(x, Integer())
Dim yy As Integer() = DirectCast(x, Integer())
Return yy(0) - xx(0)
End Function
End Class
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
"nafri" <sp****@spam.net> schrieb:
thanks, it works well, but arranges them in decreasing order. Although i
can
reverse and get it what i want, but is their anything that i can do in the
compare function to make it arrange in decreasing order.
Return yy(0) - xx(0)


=> 'Return xx(0) - yy(0)

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
nafri,
Have you tried:
Return yy(0) - xx(0)

Return xx(0) - yy(0)

Rather then compare y to x, compare x to y.

Hope this helps
Jay

"nafri" <sp****@spam.net> wrote in message
news:0C**********************************@microsof t.com... thanks, it works well, but arranges them in decreasing order. Although i
can
reverse and get it what i want, but is their anything that i can do in the
compare function to make it arrange in decreasing order.

nafri

"Herfried K. Wagner [MVP]" wrote:
"nafri" <sp****@spam.net> schrieb:
>I have array of arrays. I need to arrange them in an increased order of
> their element 0
>
> Here is what i want.
> dim InputArray()() = {{2,0,0},{1,0,0},{6,0,0},{3,0,0}}
>
> and this is the output
> outputArray()() = {{1,0,0},{2,0,0},{3,0,0},{6,0,0}}
>
> Has any body got any idea how to it.


Untested (written from scratch):

\\\
Imports System.Collections
..
..
..
Dim InputArray()() As Integer = _
New Integer()() { _
New Integer() {2, 0, 0}, _
New Integer() {1, 0, 0}, _
New Integer() {6, 0, 0}, _
New Integer() {3, 0, 0} _
}
Array.Sort(InputArray, New FooComparer)
..
..
..
Public Class FooComparer
Implements IComparer

Public Function Compare( _
ByVal x As Object, _
ByVal y As Object _
) As Integer Implements IComparer.Compare
Dim xx As Integer() = DirectCast(x, Integer())
Dim yy As Integer() = DirectCast(x, Integer())
Return yy(0) - xx(0)
End Function
End Class
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5

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

Similar topics

9
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
197
by: Steve Kobes | last post by:
Is this legal? Must it print 4? int a = {{1, 2}, {3, 4}}, *b = a; printf("%d\n", *(b + 3)); --Steve
7
by: arkobose | last post by:
hey everyone! i have this little problem. consider the following declaration: char *array = {"wilson", "string of any size", "etc", "input"}; this is a common data structure used to store...
0
by: What-a-Tool | last post by:
Ended up using the following to hide unwanted columns and set the width of a column. Now I want to re-arrange the displayed order of the columns, so I tried creating another table style and adding...
2
by: Dr Dav | last post by:
Hello all, I'm a physicist whose rewriting a numerical simulation, previously written in IDL, in C with the goal reducing runtime. As you may imagine, my C programming skills are quite poor but I...
4
by: ramyaapriya | last post by:
write a c program to sort n(1<=n<=200) integers stored in an 1-d array in non descending order .
2
by: kenrocks | last post by:
well my problem is that I can 't figure how to arrange strings in arrays in an alphabetical order. pls.. answer asap..thx..:)
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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.