By linked list do you mean
Do you mean you plan to write a class which contains an element which holds another instance of the same class and so on?
Or is there something VB can do that I haven't seen or heard of before?
I am not much for knowing what's fastest in compiled code etc, but I have found the Collection object to be useful when order is not important, and the array syntax useful when order is important.
If you plan to have an array of objects (i.e. your own classes) and if you plan on moving them about alot (sorting etc) then I would hope that linked list (class) ideas would work best.
Finally, kedaman mentioned the default property of a class you create which would seem to be the best way to implement your comparison plans. I don't know C++, but in Java, there are so many ways of customising classes and so many "standard" interfaces you can choose to implement that there is simply no comparison with VB. It will be a valiant effort I think to make VB work more like C++, but in the end, you will probably have to wait for VB7 like everyone else :)
When I switch languages after a prolonged period in another, I find it takes a couple of days to "remember" the rules. How many times I've typed Dim lResult as Long = 0 in VB I cannot count :) I hear it will be in VB7 which is cool :)
Sorry if I was too opinionated in my reply - I hope I am not normally that way :)
Cheers
Paul Lewis
Yep, you have described a linked list...
HEhe,
I was just checking on how you planned to implement the list. I am glad there wasn't a feature of VB I was totally oblivious of giving us that flexibility.
I think it would take you only a few minutes to test your idea out. You should let us know if there are major differences in speed between the two (or major differences in memory allocation or anything).
The understanding is that the array would be an array of your class right?
For only 100 items, I think it will be hard to detect a noticeable difference in speed since you no doubt develop on a fast machine.
Another point to consider: You said that the order is very important in your app, but in fact, what you really mean is that the retrieval order is very important. A linked list stores the items in an arbitary order whereas the array stores them in a fixed order. This is a subtle but important point which you no doubt know.
Therefor, if the order they are stored in is of no importance, then I prefer 'keeping it VB' and using a collection. Assign each item in the collection a key which has to be a string. It's not going to be as fast as an array but like I said, I suspect there will be a very small difference in speed if we are only talking about 100 items.
I would be interested to learn of any differences in performance between sorting an array of 100 instances of a class vs sorting the class as a linked list, vs sorting a collection (mind you, collections aren't designed or optimised for sorting).
Anyhow, if I had to read code of someone elses employing any of these methods, I'd hope that I could fathom it out so I don't think it will matter which way you do it. I always like to keep it clean and keep it simple. By clean, I mean don't go adding programming complexities if they serve no real purpose. Of course, the purpose may only be to allow you to use a particular programming paradigm that you like, but usually, you will find it easier to compromise to a certain degree...
Darn it - I've been too wordy again.
Sorry
Paul Lewis
Re: Linked Lists vs. Arrays
Quote:
Originally Posted by
Sam Finch
VB Has a linked list facility, It's called a collection. you declare one with
Code:
Dim collMyCollection As New Collection
and you can add, remove and read Items using the Add and Remove Methods and the Item Property. You can also Give your items a Key, which is a string to Identify them by use
Code:
collMyCollection.Add 10, "MyKey"
and then you can access it with
Code:
Msgbox collMycolection.Item("MyKey")
Thank you so much! It is posts like these that spare the blushes of ignoramuses like me who don't read through the whole book before starting something! This is exactly what I am looking for!