Implement a function that returns the 5th element from the
end in a singly linked list of integers in one pass.
Answer Posted / abhijit annaldas
node* getNthFromLast(node* head, int n)
{
int c;
node *nth;
while(pt!=NULL)
{
pt=pt->next;
c++;
if(c>=n)
*nth=pt;
}
if(c<n) //LL contains less than n nodes
return (*node)0;
else
return *nth;
}
Use it as..
fifth_node = getNthFromLast(head, 5);
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What is a static function in c?
When should we use pointers in a c program?
write a program to concatenation the string using switch case?
#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }
Explain function?
What is the difference between variable declaration and variable definition in c?
Explain why c is faster than c++?
What is volatile variable how do you declare it?
Who developed c language?
What math functions are available for integers? For floating point?
What is ponter?
Want to know how to write a C program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.
If errno contains a nonzero number, is there an error?
What is New modifiers?
What is new line escape sequence?