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 the use of getchar functions?
Why void is used in c?
What are the features of c language?
Can you please explain the difference between strcpy() and memcpy() function?
I came across some code that puts a (void) cast before each call to printf. Why?
Why header file is used in c?
Can you please explain the difference between exit() and _exit() function?
What are 'near' and 'far' pointers?
How do you determine whether to use a stream function or a low-level function?
Explain what is a static function?
What is external variable in c?
What is static memory allocation?
How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?
WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
What are the different data types in C?