[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.

Program Discussion :: Basics

Home > Programs > Basics

109 / 279

Write a program to find the loop in linklist and remove the loop in linklist.

Answer:

#include 
#include 
#include
using namespace std;
struct node{
    int val;
    struct node *next;
};
void print_list(struct node *head)
{
    coutnext;
    }
    coutnext;

    tmp->next = head->next;
}

void print_loop(struct node *head)
{
    int n = 25;
    coutnext)
    {
        if ((slow == fast->next) || (slow == fast->next->next ))
        {
            coutnext->next;
    }

    coutnext;
        far = far->next;
    }

    prev = far;
    far = far->next;

    while(near != far)
    {
        prev = far;
        far = far->next;
        near = near->next;
    }

    prev->next = NULL;
}

void detect_and_remove_loop(struct node *head)
{
    struct node *slow = head;
    struct node *fast = head;

    while(slow && fast->next && fast->next->next)
    {
        if ((slow == fast->next) || (slow == fast->next->next ))
        {
            coutnext->next;
    }

   cout

Asked In :: Alcatel-Lucent

Post Your Answer Here:

Language:

Post Your Reply Here:



Language:

Post Your Reply Here: