Re: [algogeeks] loop in link list

2011-08-31 Thread shady
can anyone tell why this algorithm works ? any proof for it ? On Wed, Aug 31, 2011 at 6:27 PM, rahul sharma wrote: > int loop(void *head1,void *head2) > { > //head1 and head2 initialized to start; > while(head1!=NULL && head2!=NULL) > { > head1=head1->next; > head2=head2->next->next; > if(head1==

Re: [algogeeks] loop in link list

2011-08-31 Thread ravi maggon
In one of my interview at winshuttle I was asked the same ques but their was an addon to this. Find the point where the loop occurs. For eg: 1->2->3->4->5->6->7->8->9->5 so output should be 5 can anyone give the algo for this. On Wed, Aug 31, 2011 at 6:44 PM, Piyush Grover wrote: > This is fine

Re: [algogeeks] loop in link list

2011-08-31 Thread Piyush Grover
This is fine but adding a twist to it. Find number of nodes which are not in the loop. On Wed, Aug 31, 2011 at 6:27 PM, rahul sharma wrote: > int loop(void *head1,void *head2) > { > //head1 and head2 initialized to start; > while(head1!=NULL && head2!=NULL) > { > head1=head1->next; > head2=head2-

[algogeeks] loop in link list

2011-08-31 Thread rahul sharma
int loop(void *head1,void *head2) { //head1 and head2 initialized to start; while(head1!=NULL && head2!=NULL) { head1=head1->next; head2=head2->next->next; if(head1==head2) return 1;tehre is loop; } return 0;//no loop } hi guys is it corect for finding the loop...if any test case that wont w