[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.
Interview Questions and Answers :: Hewlett Packard Enterprise

3. Write a program to find the loop in sigle linked list.

Answer:

bool loopInLinkedList(Node *list)
{
Node *slow_p, *fast_p;
slow_p = list;
fast_p = list;
while (slow_p && fast_p && fast_p->next)
{
slow_p = slow_p->next;
fast_p = fast_p->next->next;
if (slow_p == fast_p)
return TRUE;
}
return FALSE;
}

Post Your Answer Here:      Public      Private

Rate This: +3 -0
Report     

Post Your Reply Here:     

Report Error

Report Error

Please Login First Click Here