prachi jain prachi jain

#include<stdio.h>
struct node
{
    int data;
    struct node* next;
};
void checkloop(struct node **head_ref)
{
    struct node* fast=head_ref;
    struct node* slow=head_ref;
    while(fast!=NULL)
    {
        fast=fast->next;
        if(fast->next!=NULL)
        {
            fast=fast->next;
            slow=slow->next;
        }
        if(fast==slow)
        {
            printf("loop found");
            return;
        }

    }
        printf("no loop");
}
int main()
{
    struct node* head=NULL;
    struct node* first=NULL;
    struct node* a=NULL;
    struct node* b=NULL;
    struct node* c=NULL;
    head=(struct node*)malloc(sizeof(struct node));
    first=(struct node*)malloc(sizeof(struct node));
    a=(struct node*)malloc(sizeof(struct node));
    b=(struct node*)malloc(sizeof(struct node));
    c=(struct node*)malloc(sizeof(struct node));

    head->data=7;
    head->next=a;
    a->data=90;
    a->next=first;
    first->data=1;
    first->next=b;
    b->data=34;
    b->next=c;
    c->data=78;
    c->next=first;
    checkloop(&head);


}

prachi jain

prachi jain Creator

(No description available)

Suggested Creators

prachi jain