DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C (http://www.daniweb.com/forums/forum118.html)
-   -   To find whether Single Linked List is looped. (http://www.daniweb.com/forums/thread49762.html)

dilip.mathews Jul 11th, 2006 1:27 am
To find whether Single Linked List is looped.
 
Hi all,

What is the effficient way to check whether a single linked list is looped somewhere.The number of nodes in the list is not known.
In that case traversal of SLL will go into an infinite loop.

One solution I have is to store each address of node in array and compare the nest address with the address in the array. But this solution will be of order O(n*n). Can somebody give me an efficient solution.

bobd Jul 11th, 2006 2:20 am
Re: To find whether Single Linked List is looped.
 
For a discussion of detecting cycles in linked lists, see http://ostermiller.org/find_loop_sin...nked_list.html

-bobd-

dilip.mathews Jul 11th, 2006 1:51 pm
Re: To find whether Single Linked List is looped.
 
Thnks BOBD


All times are GMT -4. The time now is 8:25 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC