|
-
October 10th, 2008, 12:30 PM
#3
Re: How to find whether a linked list is a circular linked list
Wow...Zachm just wow (jumping two spots instead of one still makes it linear...).
Unless the list is a doubly linked list (forward and backward references) you don't have a choice but to do a linear search down the list until you reach the end. That's the whole point of a linked list: they are linked, one by one...
The only way to do it on a singularly linked list is to linearly traverse to the last object and see whether or not it has a reference to the "head" object. If it does, great, otherwise it should point to null.
If you have a doubly linked list then you can simply check head->previous.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|