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 4 1864
"nafri" <sp****@spam.ne t> 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.Collecti ons
..
..
..
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(Inpu tArray, New FooComparer)
..
..
..
Public Class FooComparer
Implements IComparer
Public Function Compare( _
ByVal x As Object, _
ByVal y As Object _
) As Integer Implements IComparer.Compa re
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/>
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.ne t> 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.Collecti ons .. .. .. 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(Inpu tArray, New FooComparer) .. .. .. Public Class FooComparer Implements IComparer
Public Function Compare( _ ByVal x As Object, _ ByVal y As Object _ ) As Integer Implements IComparer.Compa re 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/>
"nafri" <sp****@spam.ne t> 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/>
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.ne t> wrote in message
news:0C******** *************** ***********@mic rosoft.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.ne t> 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.Collecti ons .. .. .. 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(Inpu tArray, New FooComparer) .. .. .. Public Class FooComparer Implements IComparer
Public Function Compare( _ ByVal x As Object, _ ByVal y As Object _ ) As Integer Implements IComparer.Compa re 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/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 function (which was translated from Fortran code),
among other heinous and numerous declarations, is this bit:
static float bbuff;
static int bkey;
static int buse;
|
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
|
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 strings of any lengths
into an array of pointers to char type variable.
my problem is: given the declaration
|
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 the columns in the order I
wanted them, but for some reason I end up with all table style settings
gone. Anyone see what I'm doing wrong?
Thanks - Sean
'Hide un-wanted column
Me.DsGameInfo.Tables("Games").Columns("Home").ColumnMapping =...
|
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 am learning.
My problem is this. I had sucessfully written a C code that worked
( with considerable speedup over the IDL version ) using an array size
of 100x100. However, I am working towards making the array size closer
to 300x300. Since I had...
| |
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 .
|
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..:)
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |