Mail Archives: djgpp/1998/03/30/18:45:11
In article <3 DOT 0 DOT 5 DOT 32 DOT 19980329185251 DOT 007a4430 AT vip DOT cybercity DOT dk>, "Nils Emil P.
Larsen" <Peter_Larsen AT vip DOT cybercity DOT dk> writes:
>Can anyone show me (or tell me where to find) a good example of practical
>using of linked lists? I really don't understand what they a for, but I
>think they are important!
This question is not really djgpp specific -- a bit off topic for this
newsgroup, but while we're talking about it...
Linked lists are for situations where it is critical to be able to insert and
delete elements from an ordered series of an indefinite number of elements.
e.g. (maybe) a list of structs containing employee data arranged in
alphabetical order, when you only need to use the structs in alphabetical
order.
Since the way you access the data is by going down the chain of elements
(nodes) in order, it is very slow if you have a long list where you won't be
using the elements in order. An alternative is to have a dynamically-allocated
array of pointers to the structs. That's much faster for random access and
doesn't cost more in memory, since the structs don't need to contain a pointer
to the next struct. Of course, when you use an array you lose the ability to
insert and delete elements easily and efficiently.
Kochan's excellent _Topics in C Programming_ has a brief intro to linked lists.
There is another book with more in-depth coverage -- I believe its title is
(sorry I'm not absolutely sure) _Advanced C_ and the author has also written
books on PC graphics.
--Ed (Myknees)
- Raw text -