A list regardless would almost certainly require structs.
A struct is a custom data type. Example:
struct iDontCare
{
int i;
char string[32];
};
Is just an integer and a 32 char array.
The real benefit is when it comes to using an array of more than one type of data, or advanced data structures.
So, you would have
struct possibleTileType
{
int type;
struct possibleTileType *next,*prev;
};
The thing is, rather than refer to one like int, you must preceed it with struct. So
struct example
{
/*some data stuff goes here*/
};
To make one, you would use
struct example variable;
For example, in a roguelike, if you want each floor tile to be able to hold 0 to 10 items, one creature, and it's character, you would use
struct mapBit
{
char character;
struct creature *occupant;
struct item items[10];
};
struct mapBit[40][80];
Of course, I just realised that I forgot to mention how to access a struct.
It varies depending if it is an actual struct, or a pointer to a struct.
If an actual struct, to access property x of struct y, you use y.x
Example:
struct point
{
int x,y;
}
int main()
{
struct point a;
a.x=4;
a.y=2;
a.x++;
a.y-=a.x;
}
Very similar to a variable.
However, if you have a pointer, you use y->x rather than y.x
struct colour
{
unsigned char r,g,b;
};
void setToGreen(struct colour *c)
{
c->r=0;
c->g=255;
c->b=0;
}
I won't go into advanced subjects such as malloc() and stuff, but here is some quick example code of a 2D map
struct tile
{
char char;
float r,g,b;
};
struct tile map[40][60];
void draw()
{
int x,y;
for(x=0;x<40;x++)
{
for(y=0;y<60;y++)
{
glColor3f(map[x][y].r,map[x][y].g,map[x][y].b);
draw_char(map[x][y].char,x,y);
}
}
}
Some more complex code uses typedef so that they do not need to use struct something to refer to it. typedef just tells the compiler that some phrase means something else, similar to #define, but just for types.
(Example from openGL header file)
typedef unsigned int GLenum;
typedef unsigned char GLboolean;
typedef unsigned int GLbitfield;
typedef void GLvoid;
typedef signed char GLbyte; /* 1-byte signed */
typedef short GLshort; /* 2-byte signed */
typedef int GLint; /* 4-byte signed */
typedef unsigned char GLubyte; /* 1-byte unsigned */
typedef unsigned short GLushort; /* 2-byte unsigned */
typedef unsigned int GLuint; /* 4-byte unsigned */
typedef int GLsizei; /* 4-byte signed */
Something somewhat harder to understand, but often used, is to combine the struct definition with the typedef, like this:
typedef struct whatever{} newname, newname2;
or
typedef struct whatever
{
int a;
char b;
} newname, newname2;
However, since the typedef is incomplete during the struct definition, you must write out the full struct whatever for any pointers to the same type within the struct definition.
Now, I won't even bother trying to explain pointers, at least not in this post, as you *might* already understand them, and it's already so long...
Also, structs, or classes, are going to be essential for any sort of non-array list. And that wouldn'r be any diffrent from what you already likely have.