Ben Pfaff wrote:
Chris Dollin <ke**@hpl.hp.com> writes:
(b) if it's a cyclic (doubly-)linked list, surely it hasn't
/got/ a head and a tail?
In my experience a circular linked list usually has some
distinguished node, if only because that's the node at which new
nodes are added to the list. (Usually it's just one node, not
two.)
Yes - but the OP wanted to know how to /detect/ the head and
tail of the doubly-linked list.
Either it's external to the list (a reference to some specific
element), in which case if you don't know it you can't detect
it; or there's some marker in the list elements, which the OP
hasn't mentioned and which in any case would make it signitficantly
more than just a (cyclic) (doubly-) linked list.
--
Chris "electric hedgehog" Dollin
Il Principe - Byzantium - Hansa - Antike - King's Progress
Farfalia - Mu - Havoc - Tigris & Euphrates [kartenspiel]