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
What is a union?
What is the use of gets and puts?
How to delete a node from linked list w/o using collectons?
Explain threaded binary trees?
How is pointer initialized in c?
swap 2 numbers without using third variable?
What are the valid places to have keyword “break”?
How is a structure member accessed?
how to find binary of number?
What is the use of f in c?
What is meant by errors and debugging?
Between macros and functions,which is better to use and why?
What is adt in c programming?
the real constant in c can be expressed in which of the following forms a) fractional form only b) exponential form only c) ascii form only d) both a and b
How to write a code for reverse of string without using string functions?