sort two arrays as one?

  • Thread starter Thread starter BobAchgill
  • Start date Start date
B

BobAchgill

I have 2 arrays with identical number or rows.

arrword() as string
arrnumber() as integer

How can I best sort both arrays together using the integer array as the
column to sort by in descending numerical order?


This is what I want to achieve:
1 alive
1 beginning
1 covered
4 along
6 all
13 of
17 earth
62 and

I tried putting the two arrays into a third single column string array and
used array.sort(ThirdArray) but got these not so good results. This does not
achieve my numberical sort requirement

This is not what I want:
1 alive
1 beginning
1 covered
13 of
17 earth
4 along
6 all
62 and
 
I have 2 arrays with identical number or rows.

arrword() as string
arrnumber() as integer

How can I best sort both arrays together using the integer array as the
column to sort by in descending numerical order?

This is what I want to achieve:
1 alive
1 beginning
1 covered
4 along
6 all
13 of
17 earth
62 and

What is the relationship between the two arrays?
 
one to one

e.g.

There is 1 "alive" word
There are 17 "earth" words
There are 62 "and" words

These represent statistics of how many times these words occur in a portion
of text. I just want to sort the data into a list of most occuring to least
occuring words based on the word count column. Each word has one associated
word count number in the other array.
 
one to one

e.g.

There is 1 "alive" word
There are 17 "earth" words
There are 62 "and" words

These represent statistics of how many times these words occur in a portion
of text. I just want to sort the data into a list of most occuring to least
occuring words based on the word count column. Each word has one associated
word count number in the other array.

Ok... so they have cooresponding indexes... they are parrallel
arrays. Ok, that makes some sense. now i can think on a solution :)
 
BobAchgill,

You can sort 2 parallel arrays with Array.Sort, like this:

Array.Sort(arrnumber, arrword)

However, for words associated with the same number, this won't sort in
ascending order by word. So you might get this:

1 covered
1 beginning
1 alive
4 along
6 all
13 of
17 earth
62 and

Kerry Moorman
 
BobAchgill,

You can sort 2 parallel arrays with Array.Sort, like this:

Array.Sort(arrnumber, arrword)

However, for words associated with the same number, this won't sort in
ascending order by word. So you might get this:

1 covered
1 beginning
1 alive
4 along
6 all
13 of
17 earth
62 and

Kerry Moorman










- Show quoted text -

Funny... I never noticed that array.sort allowed that. Well, you
learn something new every day.
 
You could build yourself a 2 column DataTable...
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("TheCount", Type.GetType("System.Int32")))
dt.Columns.Add(New DataColumn("TheWord", Type.GetType("System.String")))
....
Load the rows,
....
and then sort...
dt.DefaultView.Sort = "TheCount, TheWord"
 
Tom said:
Funny... I never noticed that array.sort allowed that. Well, you
learn something new every day.
Yes, I only discovered this recently myself while trying to find a way
to sort Structures based on any Member of the Structure.

I found it very difficult to find a solution, so if anyone else is
looking for the same I'd be happy to provide the code.

Maybe the OP would be interested in merging his two (or more) arrays
into a Structure Array?

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
Back
Top