All pastes #246460 Raw Edit

Someone

public text v1 · immutable
#246460 ·published 2006-11-12 06:13 UTC
rendered paste body
Step 1 :
     Use hare and tortoise method to find whether thr exists a loop .   
     
     while(fast !=  null)
       {
	 slow = slow->next
	 fast = fast->next
	 if(fast->next)
		fast = fast->next
	}
		---- Now lets sat they meet at 'p'  which a node in the loop segment.

Step 2 :
		
	now disconnect the loop segment by the following  stat..
		
		q = p->next;
		p->next = null;

Step 3 :
	
	Now u hv two head pointers  1- head(given) 2 - q(the discoonetced part)
	Find the legth of both the list
	Find the diff btw them and move the head of the larger list (l1-l2) no of times

Step 4 :
	Now traverse both the list till the pointers are the same..!!!