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
Does c have class?
What is queue in c?
How do I get a null pointer in my programs?
What is the use of getch ()?
Why isnt there a numbered, multi-level break statement to break out
Explain what math functions are available for integers? For floating point?
What is context in c?
Which is better between malloc and calloc?
What are the types of data types and explain?
How can I direct output to the printer?
Why c language?
An integer that indentifies the position of a data item in a sequence of data items a) value b) number c) index d) all of the above
How we can insert comments in a c program?
int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;
how to introdu5ce my self in serco