collection / array question

collection / array question

Anonymous
Not applicable
208 Views
4 Replies
Message 1 of 5

collection / array question

Anonymous
Not applicable
Hi,
I have a list of numbers I need to sort.
I have Chris Rhea?'s Bubble sort routine I adapted for doubles.
That wants an array(variant) as input.
Not knowing the length of the list I either need to redim multiple times or
put in a collection, get the count and then redim once to the size I need.
I'm wondering which is better, a collection and one redim, or just one array
with multiple redims?
How much does it cost to create a collection that I'm just going to stick
into an array anyway?
Or can i sort a collection - I guess the bubble sort idea could be adapted
to work with a collection object.
Or is that plaigarism to rework something like that if you retain the
original credits info in the modified code?
Or does any of this make any sense?
Thanks for any inspirations.
Mark
0 Likes
209 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Try searching the MSDN (msdn.microsoft.com) for sorting algorithms. Here's
one hit (watch for wordwrap):

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemArrayClassSortTopic1.asp

--
Rune Wold
System Analyst
Engineering Systems
rune@engsys.no
--
0 Likes
Message 3 of 5

Anonymous
Not applicable
What format is the list in that you don't know it's size? Multiple Redim's
are not recommended if you are after performance. Doing a redim on for every
item is very slow. One idea would be to process the list once, doing nothing
but getting the count - then create the array the correct size and process
the list again, populating the array.
You can reuse the sorting code if it's something that someone posted. Even
if you modify it, including the credit is a good idea.
Glen

"MP" wrote in message
news:8F784FD741BB7C4A47572095470042E1@in.WebX.maYIadrTaRb...
> Hi,
> I have a list of numbers I need to sort.
> I have Chris Rhea?'s Bubble sort routine I adapted for doubles.
> That wants an array(variant) as input.
> Not knowing the length of the list I either need to redim multiple times
or
> put in a collection, get the count and then redim once to the size I need.
> I'm wondering which is better, a collection and one redim, or just one
array
> with multiple redims?
> How much does it cost to create a collection that I'm just going to stick
> into an array anyway?
> Or can i sort a collection - I guess the bubble sort idea could be adapted
> to work with a collection object.
> Or is that plaigarism to rework something like that if you retain the
> original credits info in the modified code?
> Or does any of this make any sense?
> Thanks for any inspirations.
> Mark
>
>
>
0 Likes
Message 4 of 5

Anonymous
Not applicable
"Glen Albert" wrote in message
news:1CC4F5715B4638838222AA8C1C57D02D@in.WebX.maYIadrTaRb...
> What format is the list in that you don't know it's size?

I'm reading it out of a dictionary which was populated by an earlier sub.

> Multiple Redim's are not recommended if you are after performance.
that's what I've heard
>Doing a redim on for every item is very slow. One idea would be to process
the list once, doing >nothing but getting the count - then create the array
the correct size and process
> the list again, populating the array.

That's what I'm doing by putting them in a collection first, then getting
the .Count. I was just checking if that is the correct proceedure. (it still
seems like double work to me)
I'll check the link posted by Rune, maybe I can sort the collection.
I guess I could just do a foreach on the xrecords and increment an integer
count but then i'd have to go back through it a second time to put them in
the array but that seems really stupid.
or (duh) the .Count of the dictionary! what a concept! :)~

> You can reuse the sorting code if it's something that someone posted. Even
> if you modify it, including the credit is a good idea.
> Glen
cool
thanks for the response
Mark
0 Likes
Message 5 of 5

Anonymous
Not applicable
Rune,
Thanks I'll check it out!
Mark
0 Likes