Implement a function that returns the 5th element from the
end in a singly linked list of integers in one pass.

Answer Posted / jishu

Answer 6 is correct and well thought but there is a tiny
mistake.

the while loop should check upto the last node which it
doesn't and hence prints the wrong value ie. value of the
node before the fifth node from the end.

while(p!=NULL) would give the correct node.

Also while returning the value, decrementing curr_ct by 5 is
not really necessary.

return a[curr_ct%5]; would give the same value in all cases.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is malloc and calloc?

575


What is the use of volatile?

611


Is there any possibility to create customized header file with c programming language?

626


What is the meaning of c in c language?

597


How do I swap bytes?

633






What is formal argument?

652


Who is the main contributor in designing the c language after dennis ritchie?

554


void main(int n) { if(n==0) return; main(--n); printf("%d ",n); getch(); } how it work and what will be its output...............it any one know ans plz reply

2226


What does %c do in c?

587


Explain heap and queue.

589


What is the advantage of using #define to declare a constant?

623


Write a program to swap two numbers without using the third variable?

598


When would you use a pointer to a function?

589


How can I run c program?

690


Write a c program to build a heap method using Pointer to function and pointer to structure ?

4179