By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,201 Members | 1,617 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,201 IT Pros & Developers. It's quick & easy.

generic linked list

P: n/a
How do I implement a generic linked list?
Feb 26 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a

<se**************@yahoo.co.inwrote in message
news:83**********************************@x30g2000 hsd.googlegroups.com...
How do I implement a generic linked list?
typedef struct node
{
struct node *prev;
struct node *next;
void *data;
} NODE;

typedef struct
{
struct node *first;
struct node *last;
} LINKEDLIST;
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Feb 26 '08 #2

P: n/a
se**************@yahoo.co.in wrote:
How do I implement a generic linked list?
What do you mean by "generic?"

--
Er*********@sun.com
Feb 26 '08 #3

P: n/a
se**************@yahoo.co.in wrote:
How do I implement a generic linked list?
Depends.
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 (*CreateDataFrom)(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.programming. 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.
Feb 26 '08 #4

P: n/a
<se**************@yahoo.co.inwrote in message
news:83**********************************@x30g2000 hsd.googlegroups.com...
How do I implement a generic linked list?
Use the list.h set of interfaces from the linux kernerl sources
Feb 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.