473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

generic linked list

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

<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Stig Brautaset | last post by:
Hi group, I'm playing with a little generic linked list/stack library, and have a little problem with the interface of the pop() function. If I used a struct like this it would be simple: ...
6
by: Nick Valeontis | last post by:
I know how to use Icomparable. However, I can't figure out how to sort a generic linked list? (without writing the algorithm) Lets say I have something like this: class...
10
by: Egghead | last post by:
Hi all, Can someone kindly enough point me to some situations that we shall or "must" use Generic Class? I can foresee the Generic Method is powerful, but I can not find a single situation that...
7
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
3
by: swetha bandaru | last post by:
what is meant by generic linked list.How to implement it in c? can anyone plz help me.
0
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be...
11
by: Scott Stark | last post by:
Hello, The code below represents a singly-linked list that accepts any type of object. You can see I'm represting the Data variable a System.Object. How would I update this code to use...
4
by: Tony Johansson | last post by:
Hello! What actually does this sentence mean? Create a linked-list generic class that enables you to create a chain of different objects types. When I create a linked-list generic class for...
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.