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 the use of getchar functions?

897


Why void is used in c?

756


What are the features of c language?

799


Can you please explain the difference between strcpy() and memcpy() function?

795


I came across some code that puts a (void) cast before each call to printf. Why?

927






Why header file is used in c?

747


Can you please explain the difference between exit() and _exit() function?

805


What are 'near' and 'far' pointers?

795


How do you determine whether to use a stream function or a low-level function?

885


Explain what is a static function?

821


What is external variable in c?

780


What is static memory allocation?

819


How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?

785


WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.

2225


What are the different data types in C?

918