If you've a finite set of possible node type, then you may define a
struct
for each node type, and store, in every node both
<ul><li>a pointer of the actual data structure, as <code>void *</code>.</li>
<li>a integer value representing the actual type of the data.</li>
(of course you've also to store a pointer to the next item of the list...)
for instance:
typedef struct tagPoint
{
int x;
int y;
}Point;
typedef struct tagUser
{
const char * name;
int age;
} User;
typedef enum TagNodeType
{
ePoint,
eUser,
eNODETYPES
} NodeType;
typedef struct TagListItem
{
NodeType nt;
void * pData;
struct TagListItem * pNext;
} ListItem;
Then implement a
addListItem
function accepting a pointer to actual data and a value representing the data type.
On retrieving data you've to check the
nt
field in order to properly cast the
pData
pointer.
:)