Linked list example?

Started by
11 comments, last by Strife 23 years, 5 months ago
Hey, does anyone know of an example that implements a linked list in a game, preferably with classes? I understand the basics of linked lists, but I''d kinda like to see some more in-depth examples than what I have seen, which basically consist of nodes that basically only show something like name and age or whatever. Any replies would be helpful. Excuse me whilst I conquer Earth... Commander M (a.k.a. Crazy Yank) http://commanderm.8m.com CmndrM@gdnmail.net
Advertisement
Linked lists are very important in games, mostly in the form of holding animations, and of course, BSP trees. Look up the quake source.

-----------------------------

A wise man once said "A person with half a clue is more dangerous than a person with or without one."

The Micro$haft BSOD T-Shirt
-----------------------------A wise man once said "A person with half a clue is more dangerous than a person with or without one."The Micro$haft BSOD T-Shirt
Actually, I was thinking more of using them for holding game objects (specifically, like an enemy or something), since an array isn''t so useful here (especially since the enemies are supposed to be able to be killed )

Excuse me whilst I conquer Earth...

Commander M
(a.k.a. Crazy Yank)
http://commanderm.8m.com
CmndrM@gdnmail.net
Hi,
Just define a node class, that holds your game object as it''s element. The Node should also hold a reference to the next (and possibly previous) Node in the list.
In this way, you can have arbitrary nodes storing objects, which you can resuse for different apps.
Then define a linked list class, that has the usual methods insert first/last etc.
If you want some code or something, mail me.. Todd.
Toddhau.yahoo.com.au
ImmaGNUman,
Actually BSP trees are usually implemented as binary trees, rather than linked lists
(Don''t you just hate picky people like me? )
Hullo,

I was just wondering, is a link to the previous node required in a linked list? Wouldn''t it save a lot of memory to go without one? Also, is it more efficient to create a linked list object or just have functions, like in C?

P.S. - What is a BSP tree? I''ve heard of them, but I have no idea what they are.

"When i was a child I caught a fleeting glimpse, out ofthe corner of my mind. I turned to look, but it was gone, I cannot put my finger on it now. The child hasgrown, the dream has gone." -Pink Floyd
quote:Original post by Gregor_Samsa

I was just wondering, is a link to the previous node required in a linked list? Wouldn''t it save a lot of memory to go without one? Also, is it more efficient to create a linked list object or just have functions, like in C?

P.S. - What is a BSP tree? I''ve heard of them, but I have no idea what they are.


A link is required to the prior element if you want efficient deletion of random items. This way you can reference the prior item quickly and link it up the item after the item you just deleted.

As for BSP trees, a BSP tree is a tree that grows the delicious BSP fruit.





_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
A BSP tree is a way of performing hidden surface removal in 3D apps. Its basically a way of dividing the 3D space into sectors and only showing the ones visible to the player.

There''re lots of tutorials in the programming section here on GD.

Hello.
I''ve got a great linked list class that is Template based.
the code is very simple and there is also a demo program.
I can give it to anyone, just ask for it from:
preshel@mailcity.com

I will send you the zip file.
check out the Donuts example from the DX7 SDK in the DDraw directory
it uses a doublely linked list

This topic is closed to new replies.

Advertisement