Live data from Hacker News

Linked lists in C, with open source ADT

xanthu.com

1–10 of 43 posts

Re: Linked lists in C, with open source ADT

#3

This is week-one stuff of a CS degree or on the job training. If you don't know this you shouldn't be programming.

Not everyone went to university, and people have to learn from somewhere. It is also only an introduction, there will be more complicated data structures shown soon, and algorithms. No point in jumping into the heavier stuff. Trying to help people who are new to C.

Re: Linked lists in C, with open source ADT

#6

This is week-one stuff of a CS degree or on the job training. If you don't know this you shouldn't be programming.

Not everyone went to university, and people have to learn from somewhere. It is also only an introduction, there will be more complicated data structures shown soon, and algorithms. No point in jumping into the heavier stuff. Trying to help people who are new to C.

[deleted]

Re: Linked lists in C, with open source ADT

#7
post #5

The book _C Interfaces and Implementation_ is nothing but library interfaces like this and their implementations. You are, for whatever it's worth, better off defaulting to a variable-length array than to a linked list.

Someone wants to know about linked lists, and your comment is to use some other data structure that has a different purpose?

Re: Linked lists in C, with open source ADT

#8

This is week-one stuff of a CS degree or on the job training. If you don't know this you shouldn't be programming.

Not everyone went to university, and people have to learn from somewhere. It is also only an introduction, there will be more complicated data structures shown soon, and algorithms. No point in jumping into the heavier stuff. Trying to help people who are new to C.

Is it appropriate for Hacker News though? It fits better on http://www.reddit.com/r/learnprogramming

Re: Linked lists in C, with open source ADT

#9
Some simple suggestions:

1. Please align the asterisks properly. It hurts eyes.

2. Access by index?

3. Iterator (callback on each element)

4. use 'init' instead of 'initialize'. Extra typing hurts fingers.

Re: Linked lists in C, with open source ADT

#10
This isn't how I'd do a linked list in C. Having to malloc separate storage for the next/prev pointers imposes a big cost in terms of performance (it's hardly O(1)) and robustness. Your linked list operations can all fail now - sooner or later, that's going to put you in a very tight spot.

I prefer to store next/prev pointers with the data itself, and to use offsetof/containerof to find a pointer to the data struct which contains a given set of next/prev pointers.

One example of such an scheme is the list used in the Linux kernel:

http://lxr.linux.no/#linux+v3.7.3/include/linux/list.h

http://lwn.net/Articles/336255/

Post reply on HN