How do I implement a generic linked list?
generic linked list
Collapse
This topic is closed.
X
X
-
sengupta_arka123@yahoo.co.inTags: None -
Malcolm McLean
Re: generic linked list
<sengupta_arka1 23@yahoo.co.inw rote in message
news:83e5b7a5-a7d1-4bbd-9987-0f9da6935ea8@x3 0g2000hsd.googl egroups.com...typedef struct nodeHow do I implement a generic linked list?
{
struct node *prev;
struct node *next;
void *data;
} NODE;
typedef struct
{
struct node *first;
struct node *last;
} LINKEDLIST;
--
Free games and programming goodies.
-
Eric Sosman
Re: generic linked list
sengupta_arka12 3@yahoo.co.in wrote:What do you mean by "generic?"How do I implement a generic linked list?
--
Eric.Sosman@sun .com
Comment
-
Michael Mair
Re: generic linked list
sengupta_arka12 3@yahoo.co.in wrote:Depends.How do I implement a generic linked list?
The usual way is to have a struct containing
the list infrastructure and a pointer to the data
and provide ways for the user to affect the data,
e.g. via function pointers.
With
struct GenSLList {
struct GenSLList *pNext;
void *pData;
};
you can perform some operations purely on the linked list,
like inserting new nodes
struct GenSLList *pNode1, *pNode2;
....
pNode1->pNext = pNode2;
whereas things like creating new nodes, deleting nodes, sorting
the list etc. need your input:
struct GenSLList*
CreateSllNode (int (*CreateDataFro m)(void**, void*),
void *pTemplateData) ;
which provides a new list node and, depending on the CreateDataFrom
and pTemplateData parameters, may do things to also provide
new data or set the pData member to pTemplateData or ...
Note that general programming / algorithm / data structure questions
may be better asked in comp.programmin g. As soon as you have written
some C code and have specific questions regarding that code, you can
ask here.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Comment
-
Ravishankar S
Re: generic linked list
<sengupta_arka1 23@yahoo.co.inw rote in message
news:83e5b7a5-a7d1-4bbd-9987-0f9da6935ea8@x3 0g2000hsd.googl egroups.com...Use the list.h set of interfaces from the linux kernerl sourcesHow do I implement a generic linked list?
Comment
Comment