i've got several linked lists in my program they _all_ have 1 or more
data elements and a next pointer that points to the next item in the list
or NULL if the end.
For this example, let's assume i've got 3 linked lists:
typedef struct list_a lista_t;
struct list_a {
int *data;
lista_t *next;
}
typedef struct list_b listb_t;
struct list_b {
float *data;
listb_t *next;
}
typedef struct list_c listc_t;
struct list_c {
lista_t *item;
listb_t *item2;
listc_t *next;
}
Each list holds a different type of data, i have functions to add and display
data from these lists:
void AddA (int input; lista_t **list);
void AddB (float input; listb_t **list);
void AddC (lista_t *one; listb_t *two; listc_t **list);
void DisplayA (lista_t *list);
void DisplayB (listb_t *list);
void DisplayC (listc_t *list);
they all do similar things, go through the list, element by element, writing
the data to stdout, DisplayC goes through both lists at the same time display-
ing both data elements like this:
A_DATA1 : B_DATA1
A_DATA2 : B_DATA2
... : ...
add adds items and there are 3 add functions, one per list.
Ok, now i've described the (totally made up) lists, here's the question:
can i make it so i only have 1 display and 1 add function that works for
ALL the lists? so all i have to do is call Add with the data (the actual
code in each add function is identical except for the list data type and
the input data)
i thought about something like this:
void DisplayList (void *list);
then to use it you cast the void to whatever list type you're using, but
that's as far as i got.
[this reads a bit like an exam question doesn't it!]
--
>> I Like England Just Fine, But I Ain't Eating Any Of That Beef <<
<< MailTo: root <at> kermit "dot" globalnet /dot\ co 'dot' uk >>
>> De Chelonian Mobile <<