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 sequential access file?
How do you generate random numbers in C?
Why C language is a procedural language?
what is recursion in C
Explain what are header files and explain what are its uses in c programming?
What does dm mean sexually?
Is c still relevant?
write a c program to print the next of a particular no without using the arithmetic operator or looping statements?
Explain low-order bytes.
When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?
Explain how do you search data in a data file using random access method?
What are multidimensional arrays?
What is the return type of sizeof?
What are the advantages of c language?
Can variables be declared anywhere in c?