| 9.2.1.3 Generalised List Data TypeIn many C programs you will see various implementations and re- implementations of lists and stacks, each tied to its own particular project. It is surprisingly simple to write a catch-all implementation, as I have done here with a generalised list operation API in `list.h' :
The trick is to ensure that any structures you want to chain together have their forward pointer in the first field. Having done that, the generic functions declared above can be used to manipulate any such chain by casting it to For example:
The implementation of the list manipulation functions is in `list.c' :
|