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                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
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 to check whether a linked list is circular.
 Question Submitted By :: Coder_1
I also faced this Question!!     Rank Answer Posted By  
 
  Re: how to check whether a linked list is circular.
Answer
# 1
Create two pointers, each set to the start of the list.
Update each as follows:

while (pointer1) {
 pointer1 = pointer1->next;
 pointer2 = pointer2->next; if (pointer2)
pointer2=pointer2->next;
 if (pointer1 == pointer2) {
   print (\"circular\n\");
 }
}

If a list is circular, at some point pointer2 will wrap
around and be either at the item just before pointer1, or
the item before that. Either way, it?s either 1 or 2 jumps
until they meet.
 
Is This Answer Correct ?    8 Yes 2 No
Coder_1
 
  Re: how to check whether a linked list is circular.
Answer
# 2
start = pointer;

while(pointer)
{ 
  if(pointer->next == start)
     printf("Circular");
   pointer = pointer->next;
}
printf("Non-Circular");
 
Is This Answer Correct ?    5 Yes 10 No
Karunanidhi
 
 
 
  Re: how to check whether a linked list is circular.
Answer
# 3
consider home pointer as the starting pointer of the linked 
list.
consider temp as the temporary pointer.


temp = home;
while(temp != NULL)
{
    if(temp -> next == start)
    {
           flag = 1;
           break;
    }
    else 
           flag = 0;
temp = temp -> next;
}

if(flag == 1)
   printf("Circular");
else
   printf("Not circular");
 
Is This Answer Correct ?    4 Yes 5 No
Shruti
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
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. Microsoft7
What is the output of the program given below main() { signed char i=0; for(;i>=0;i++) ; printf("%d\n",i); }  1
programming in c lanugaue programm will errror error with two header file one as stdio.h and other one is conio.h  1
program to find magic aquare using array HCL3
main() { struct student { char name[30]; struct date dob; }stud; struct date { int day,month,year; }; scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year); }  1
main() { int i; float *pf; pf = (float *)&i; *pf = 100.00; printf("\n %d", i); } a. Runtime error. b. 100 c. Some Integer not 100 d. None of the above HCL1
void main() { int i=5; printf("%d",i+++++i); }  1
main() { printf("%x",-1<<4); }  1
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.  5
void main() { char a[]="12345\0"; int i=strlen(a); printf("here in 3 %d\n",++i); }  1
Find your day from your DOB? Microsoft12
main() { static int a[3][3]={1,2,3,4,5,6,7,8,9}; int i,j; static *p[]={a,a+1,a+2}; for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j), *(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i)); } }  1
main() { { unsigned int bit=256; printf("%d", bit); } { unsigned int bit=512; printf("%d", bit); } } a. 256, 256 b. 512, 512 c. 256, 512 d. Compile error HCL1
main(){ unsigned int i; for(i=1;i>-2;i--) printf("c aptitude"); }  1
main() { int i=-1; +i; printf("i = %d, +i = %d \n",i,+i); }  1
#ifdef something int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing); }  1
void main() { void *v; int integer=2; int *i=&integer; v=i; printf("%d",(int*)*v); }  1
main() { int c = 5; printf("%d", main||c); } a. 1 b. 5 c. 0 d. none of the above HCL1
Program to Delete an element from a doubly linked list. Infosys4
main() { int i, j; scanf("%d %d"+scanf("%d %d", &i, &j)); printf("%d %d", i, j); } a. Runtime error. b. 0, 0 c. Compile error d. the first two values entered by the user HCL1
 
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