Find the middle node in the linked list??
(Note:Do not use for loop, count and count/2)

Answers were Sorted based on User's Feedback



Find the middle node in the linked list?? (Note:Do not use for loop, count and count/2)..

Answer / kstarmind

Keep two pointers,
1. fast pointer moves two nodes at a time
2. slow pointer moves one node at a time

keep moving both the pointers, once the fast pointer reaches
the end node, your slow pointer would be at middle of the list.

Is This Answer Correct ?    47 Yes 5 No

Find the middle node in the linked list?? (Note:Do not use for loop, count and count/2)..

Answer / om

just use recursion .....it's simple......

Is This Answer Correct ?    4 Yes 3 No

Find the middle node in the linked list?? (Note:Do not use for loop, count and count/2)..

Answer / santhoshr

It wont work exactly if the no of nodes is not given!!! So
better answer is having two pointers from first itslf.
And like this , another question is there,
to find the pth node from last!! That too haas the same logic!!!

Is This Answer Correct ?    2 Yes 1 No

Find the middle node in the linked list?? (Note:Do not use for loop, count and count/2)..

Answer / kar..

move the front pointer and rear pointer at equal
intervel,these both pointe will meet at one node is middle...

Is This Answer Correct ?    2 Yes 3 No

Find the middle node in the linked list?? (Note:Do not use for loop, count and count/2)..

Answer / dhr

it also works

Is This Answer Correct ?    1 Yes 3 No

Find the middle node in the linked list?? (Note:Do not use for loop, count and count/2)..

Answer / vadivel

U mean without any looping statements r just for loop?????
It can be done in a single traversal using Hare n turtle
method as said above using a for or while loop.....
Without using looping statements d list can't be traversed..
Plz make the question clear.....

Is This Answer Correct ?    3 Yes 10 No

Post New Answer

More C Interview Questions

Without Computer networks, Computers will be half the use. Comment.

0 Answers  


Write a function expand(s1,s2) that expands shorthand notations like a-z in the string s1 into the equivalent complete list abc...xyz in s2 . Allow for letters of either case and digits, and be prepared to handle cases like a-b-c and a-z0-9 and -a-z. z-a:zyx......ba -1-6-:-123456- 1-9-1:123456789987654321 a-R-L:a-R...L a-b-c:abbc

0 Answers  


. A database table called PERSON contains the fields NAME, BASIC and HRA. Write a computer program to print a report which employee name and total salary for those employees whose total salary is more than 10,000. Total Salary = BASIC + HRA. At the end, the program should also print the total number of employees whose total salary is more than 10,000.

1 Answers  


where can function pointers be used?

2 Answers  


What are the output(s) for the following ? #include char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); }

0 Answers   Wilco,






how does a general function , that accepts an array as a parameter, "knows" the size of the array ? How should it define it parameters list ?

2 Answers   Patni, TCS,


Consider a language that does not have arrays but does have stacks as a data type.and PUSH POP..are all defined .Show how a one dimensional array can be implemented by using two stacks.

3 Answers   Google,


two variables are added answer is stored on not for third variable how it is possible?

3 Answers  


what is the maximum limit of row and column of a matrix in c programming. in linux .

4 Answers   NIIT,


Is anything faster than c?

0 Answers  


main() { int i,j,A; for(A=-1;A<=1;A++) prinf("%d\t",!!A); }

6 Answers  


What could possibly be the problem if a valid function name such as tolower() is being reported by the C compiler as undefined?

0 Answers  


Categories