473,322 Members | 1,734 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,322 software developers and data experts.

cyclic doubly link list

Hi,
how to detect head and tail in cyclic doubly link list ?
Thanks,
Cric

Nov 15 '05 #1
5 3208
fr*******@yahoo.com wrote:
Hi,
how to detect head and tail in cyclic doubly link list ?
Thanks,
Cric


Why do you need to detect its head and tail?

The simplest way would be to keep a pointer to the head and tail, and
compare the address of the current element with those pointers.

Another way would be to keep a flag inside the link node structure
describing what type of node it is (head node, tail node, middle node).

--
Simon.
Nov 15 '05 #2
fr*******@yahoo.com wrote:
Hi,
how to detect head and tail in cyclic doubly link list ?


(a) this is not a C problem.

(b) if it's a cyclic (doubly-)linked list, surely it hasn't
/got/ a head and a tail?

--
Chris "electric hedgehog" Dollin
Il Principe - Byzantium - Hansa - Antike - King's Progress
Farfalia - Mu - Havoc - Tigris & Euphrates [kartenspiel]
Nov 15 '05 #3
Chris Dollin wrote:
fr*******@yahoo.com wrote:
Hi,
how to detect head and tail in cyclic doubly link list ?
(a) this is not a C problem.


Agreed.

(b) if it's a cyclic (doubly-)linked list, surely it hasn't
/got/ a head and a tail?


Not necessarily; sometimes you need the notion of head and tail
or appropriate sentinel list nodes for a part of the algorithms
working on your data structure and cyclicality for others.
However, AFAIR whenever I have seen that, it involved head and
tail nodes not carrying information of any kind and flags to
signal isHead/isTail; I do not remember whether the cyclicality
was really necessary in these cases.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #4
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.)
--
"...what folly I commit, I dedicate to you."
--William Shakespeare, _Troilus and Cressida_
Nov 15 '05 #5
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]
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: D. Beckham | last post by:
I wrote the following code to create a short doubly-link list of three strings: "one", "two", and "three". I would like to know if I set them up correctly, so that they point to one another. ...
270
by: Jatinder | last post by:
I found these questions on a web site and wish to share with all of u out there,Can SomeOne Solve these Porgramming puzzles. Programming Puzzles Some companies certainly ask for these...
3
by: surrealtrauma | last post by:
I want to ask what's the differences between doubly liked list and linear liked list, and also the circular doubly liked list in terms of implementation. THX
4
by: dssuresh6 | last post by:
Whether browsing forward or backward can be done using a singly linked list. Is there any specific case where a doubly linked list is needed? For people who say that singly linked list allows...
8
by: sudhirlko2001 | last post by:
How to swap two nodes of doubly Linklist
0
by: drewy2k12 | last post by:
Heres the story, I have to create a doubly linked list for class, and i have no clue on how to do it, i can barely create a single linked list. It has to have both a head and a tail pointer, and...
4
by: srad | last post by:
Hi..Im writting a doubly link list in c++,compiled with Turbo c++, but my Add_at_first method seems not working,i couldnt find any problem in the code... here is the code : #include <iostream.h>...
3
by: maruf.syfullah | last post by:
Consider the following Class definitions: class AClass { int ai1; int ai2; public: CClass* c; AClass(){}
5
by: adam.kleinbaum | last post by:
Hi there, I'm a novice C programmer working with a series of large (30,000 x 30,000) sparse matrices on a Linux system using the GCC compiler. To represent and store these matrices, I'd like to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.