Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Phil Carmody <thefatphil_demunged@yahoo.co.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Circular Link List program doesn't run |
| Date | 2011-10-03 20:10 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <87ehyut30y.fsf@bazspaz.fatphil.org> (permalink) |
| References | <8ceb0f1f-92f5-4926-a66d-e6a726f09af8@t11g2000yqk.googlegroups.com> <741023e0-e416-45ef-891d-e6531808b90b@u6g2000vbo.googlegroups.com> <slrn3vfsj85iia.5l2.ike@sverige.freeshell.org> <j5uuoc$e3i$1@dont-email.me> |
James Kuyper <jameskuyper@verizon.net> writes: > On 09/28/2011 03:18 AM, Ike Naar wrote: > > On 2011-09-27, Fred <fred.l.kleinschmidt@boeing.com> wrote: > >> On Sep 27, 10:46?am, Maxx <grungeddd.m...@gmail.com> wrote: > >>> [...] > >> Your init() method is flawed. For each new node, you set l->next=l > >> so the final node's "next" pointer points to itself, not to the first > >> node. > > > > It looks as if Maxx marks the end of the list with a node > > that links to itself, instead of using the more customary convention > > of letting the last node link to NULL. > > Marking the last node with a link to NULL is the convention in a linear > list, but the subject line says that this is supposed to be a circular > linked list. A one-element circularly linked list should be linked to > itself. That's one way, but is not the linux implementation, for example. The list object (which is just a pointer or a pointer pair for doubly-linked lists) points to the first node, that node points back to the head object. > However, it should not remain linked to itself after other > elements are added to the list. That's certainly true. > > Although his method is unconventional, it is not wrong in itself, > > and I've seen situations where it works well. > > One drawback is that the list cannot be empty; that is probably > > the reason why Maxx initializes his list with a single element. > > A circularly linked list can be pointed at by pointing at any element of > the list; having that pointer be null is the way to indicate an empty list. For singly linked lists, almost always, but it doesn't have to be. The head object could point to itself, rather than at any nodes. In particular in linux' implementation, doubly-linked lists are always that way, with the list object pointing to itself in both directions. Phi -- "Religion is what keeps the poor from murdering the rich." -- Napoleon
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Circular Link List program doesn't run Maxx <grungeddd.maxx@gmail.com> - 2011-09-27 10:46 -0700
Re: Circular Link List program doesn't run Fred <fred.l.kleinschmidt@boeing.com> - 2011-09-27 12:16 -0700
Re: Circular Link List program doesn't run Ike Naar <ike@sverige.freeshell.org> - 2011-09-28 07:18 +0000
Re: Circular Link List program doesn't run Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-28 11:03 +0100
Re: Circular Link List program doesn't run James Kuyper <jameskuyper@verizon.net> - 2011-09-28 07:00 -0400
Re: Circular Link List program doesn't run Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-10-03 20:10 +0300
Re: Circular Link List program doesn't run Maxx <grungeddd.maxx@gmail.com> - 2011-09-28 10:54 -0700
Re: Circular Link List program doesn't run James Kuyper <jameskuyper@verizon.net> - 2011-09-28 15:04 -0400
Re: Circular Link List program doesn't run Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-27 20:21 +0100
Re: Circular Link List program doesn't run Maxx <grungeddd.maxx@gmail.com> - 2011-09-28 10:53 -0700
csiph-web