yay for nodes I say, they make adding dynamic content easy when making a class of nodes, each class will contain something, it can be numbers and stuff variables and functions that will affect and work and stuff. Virtually anything you want to store there but not only that, each node class will be pointing to the next node class, so they will contain a pointer. This is very useful for having dynamic data.
Picture this, you have a ball, the ball bounces around. You have two balls doing this, no prob. You want to add a bunch of balls that do different things by themselves, we might have a problem. Specially since computer works rather linearly, each line of code is executed one at a time so how can you even have several objects doing things at the same time. Well you can have each ball pointing to the next one and then all you need is to go from one ball to another calculating the behavior and when you reach the end of the list of nodes you begin again. and suddenly, we have the impression that we have object oriented programing! since each object will require some time of the machine to calculate its behavior, since the machine tends to be fast (unless you have enough calculations to slow down your pc in each object)
now here is an example of stuff in c++
class ball
{
//some variables
public:
ball();
~ball();
void behavior();
ball *next;
};
so then we can create a pointer that will always point to the first element and a pointer that will move in a way that it will stop when
pointer->next == NULL
=D FUN
but I say this is not the only approach to have some dynamic objects you can add dynamically and access them one by one.
we could have an array of pointers. actually a dynamic array of pointers.
here we have someting like that
class pointaray
{
int size, **data;
public:
pointaray();
pointaray(int);
~pointaray();
int value(int);
void set(int,int);
void add();
void del(int);
};
yeah doesn't explain much that but with several functions I can create some objects, destroy some objects, and dynamically modify the array and add elements by going
data[x] = new int;//and or any other class I want to handle there.
this method loosely explained here, well has some advantages and some bad stuff. the good thing is you can quickly access a point in the array if you know the number, the bad stuff is you have to have more functions.
While the other method just go to the next, but you have to crawl one by one. Well some ideas and tools you might need to use in the future.
Friday, March 28, 2008
NODES! and dynamic stuff
Subscribe to:
Post Comments (Atom)


























No comments:
Post a Comment