Get Off-Campus Placement Jobs Info !!!
Programs asked in Mettl Coding Round
Click To Practce List of Programs asked in Nagarro !!!

Program Discussion :: Basics

Home > Programs > Basics

5 / 248

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: