Skip to main content
GameDev.net gamedev.net
🔒 Locked

Lists, OO

Started by Damage_Incorporated Apr 26, 2003 at 5:04 PM 2 replies 600+ views
Original Post
Damage_Incorporated
Damage_Incorporated
HI, I''ve decided that OO would be neat to know. Been using C/C++ for a while and I thought I would have a go at OO(have a Java class in school ). Though about doing a list implementation and I started thinking about a fast implementation, now just making a linked list makes it _very_ easy to append elements to it but well traversing it is _slow_... How about an array? Sure fast access but what if theres not enough space for a realloc? Move the entire list doesnt sound that tempting... So this is what i figured would be neat I just make an array of pointers to each object in the list sure i have to use realloc if the index doesnt fit but thats at least better than moving a list of perhaps int[100]. This seems to be the best way to do it altho if im making a list of chars i would prolly be better off with just an array since they are smaller than a pointer but this scales better with larger structures, should provide somewhat fast access and adding elements. The reason i posted(yes I actually had one ) is that im wondering if anyone could figure out a better way of doing this perhaps this is an extremly crappy way or something, any suggestions/ideas would be greatly appriciated - Damage Inc.
Zipster
Zipster
Sounds like you've partly described a hash table An array of pointers, each element being the head (or tail) of a linked list itself (i.e a pointer). While I don't think it's standard yet, the hash_map object implements a hash table for you.

Other than that, I can't tell you of a "better" way of doing anything, because you haven't described the problem you are trying to solve! Arrays are good for certain circumstances, and linked lists for others, but hash maps also aren't the golden solution. It really depends on what you intend to use them for.

[edited by - Zipster on April 26, 2003 6:24:12 PM]
Damage_Incorporated
Damage_Incorporated
well its not for a *special* purpose its simply gonna be a template for lists of *any* kind. its simply to make it easy for myself if i want speed i will still have to hardcode it for whatever purpose i want, just want a simple template for a list that doesnt have to be 120% optimized just easy to manage and use btw gonna look up hash tables

- Damage Inc.
Arild Fines
Arild Fines
If you are trying to learn about OO, why bring the intricacies of correct datastructure design into it?



"Laughter means distance. Where laughter is absent, madness begins. The moment one takes the world with complete seriousness one is potentially insane. The whole art of learning to live means holding fast to laughter; without laughter the world is a torture chamber, a dark place where dark things will happen to us, a horror show filled with bloody deeds of violence."
-- Jens Bjørneboe
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.