Re: Two dimensional sort
- From: "David Lee Conley" <conley3500@xxxxxxxxxxxxx>
- Date: Thu, 09 Jun 2005 12:40:19 GMT
"Ali Chambers" <info@xxxxxxxxxxxxxxxxxx> wrote in message
news:1118320349.942464.38340@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> I have a two arrays that I wish to sort. One is the index array (full
> of floating point values). The other is a string array:
>
> ARRAY 1 ARRAY 2
> ------- --------
> -1.2 textA
> 12 textB
> 23.5 textC
> -100.2 textD
>
> I'd like to sort by Array1 but also change the order in Array 2:
>
> ARRAY 1 ARRAY 2
> ------- --------
> 23.5 textC
> 12 textB
> -1.2 textA
> -100.2 textD
>
> How would I do this in VB.NET?
>
> Thanks,
> Alex
>
If the two arrays are parallel (i.e., they have different data, but the data
are related and the arrays are the same size), you sort array 1 and use the
same indexing to sort array 2. For example:
Dim i as Integer
dim dblTemp as double
dim strTemp as string
For i = 0 to (array size -1)
if array1(i) < array(i + 1) then
' Swap the values
dblTemp = array1(i)
array1(i) = array1(i + 1)
array1(i + 1) = dbleTemp
strTemp = array2(i)
array2(i) = array2(i + 1)
array2(i + 1) = strTemp
endif
next i
NOTE: This is NOT a complete sorting algorithm. I'm assuming you already
know that part. If not, do a google search for "selection sort" algorithm.
Dave
.
- References:
- Two dimensional sort
- From: Ali Chambers
- Two dimensional sort
- Prev by Date: Two dimensional sort
- Next by Date: Re: Nothing or Dispose?
- Previous by thread: Two dimensional sort
- Next by thread: Re: Two dimensional sort
- Index(es):
Relevant Pages
|