ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
How will u find whether a linked list has a loop or not?
 Question Submitted By :: Vadivel152
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How will u find whether a linked list has a loop or not?
Answer
# 1
findloop(struct node *start)
{
 struct node *ptr,*ptr1;
start=ptr;

 while(ptr!=NULL)
{
  ptr1=ptr->next;
  
  while(ptr1!=NULL)
  {
     if(ptr1->link==ptr->link)
     {
        printf("\nLoop found at %d node",ptr->data);
        exit(0);
       }
    ptr1=ptr1->link;
}
ptr=ptr->link;
}
printf("\nNo Loop found in list");
}
 
Is This Answer Correct ?    6 Yes 2 No
S.v.prasad Reddy
 
  Re: How will u find whether a linked list has a loop or not?
Answer
# 2
BOOL findloop(struct node *start)
{
 struct node *ptr,*ptr1;
 ptr=start;
 ptr1= start->next;
 while(ptr!=NULL && ptr->next!=null && ptr1->next!=null && 
ptr1->next->next!=null)
   {
     if(ptr==ptr1)
          return FALSE;
     ptr=ptr->next;
     ptr1=ptr1->next->next;
   }
  return TRUE;
}
 
Is This Answer Correct ?    6 Yes 0 No
Sivaraj
 
 
 
  Re: How will u find whether a linked list has a loop or not?
Answer
# 3
the approach is to mark the nodes starting from the head.and
follow the links.
in the process if you find a node already marked then there
is loop.
 
Is This Answer Correct ?    4 Yes 0 No
Sanyam
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
write a program to Insert in a sorted list Microsoft4
how to return a multiple value from a function? Wipro1
How will u find whether a linked list has a loop or not? Microsoft3
What is "far" and "near" pointers in "c"...?  2
Program to find the largest sum of contiguous integers in the array. O(n)  5
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it. Microsoft4
Given an array of size N in which every number is between 1 and N, determine if there are any duplicates in it. You are allowed to destroy the array if you like. Microsoft8
Link list in reverse order. NetApp7
how to return a multiple value from a function? Wipro4
How can u say that a given point is in a triangle? 1. with the co-ordinates of the 3 vertices specified. 2. with only the co-ordinates of the top vertex given.  1
1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we replace the value of the j then anser is different?why? 2)int i=5; printf("%d",i++ + i++ + i++); this givs 18. Infosys3
program to Reverse a linked list Ness-Technologies3
Write a function to find the depth of a binary tree. Adobe4
You are given any character string. Find the number of sets of vowels that come in the order of aeiou in the given string. For eg., let the given string be DIPLOMATIC. The answer returned must be "The number of sets is 2" and "The sets are "IO and AI". Vowels that form a singleton set must be neglected. Try to post the program executable in gcc or g++ or in java.  2
How do I write a program to print proper subset of given string . Eg :input: abc output:{},{a},{b},{c},{a,b},{a,c},{b,c}, {a,b,c}.I desperately need this program please mail me to saravana6m@gmail.com Deshaw8
write the function. if all the character in string B appear in string A, return true, otherwise return false. Google7
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.  5
Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all. Microsoft2
String reverse with time complexity of n/2 with out using temporary variable. NetApp7
to remove the repeated cahracter from the given caracter array. i.e.., if the input is SSAD output should of SAD Synergy6
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com