468,484 Members | 1,601 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,484 developers. It's quick & easy.

generic linked list

How do I implement a generic linked list?
Feb 26 '08 #1
4 4902

<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
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
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
<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.

Similar topics

15 posts views Thread by Stig Brautaset | last post: by
6 posts views Thread by Nick Valeontis | last post: by
10 posts views Thread by Egghead | last post: by
7 posts views Thread by =?Utf-8?B?Sm9lbCBNZXJr?= | last post: by
reply views Thread by Atos | last post: by
11 posts views Thread by Scott Stark | last post: by
4 posts views Thread by Tony Johansson | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.