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
How many types of operators are there in c?
What is the function of this pointer?
Explain data types & how many data types supported by c?
What is use of pointer?
What is external variable in c?
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }
c program to compute AREA under integral
How to create struct variables?
Can the curly brackets { } be used to enclose a single line of code?
Explain high-order bytes.
Which programming language is best for getting job 2020?
Define the scope of static variables.
What is a pointer in c?
Study the following C program :call_me (myvar)int myvar;{ myvar +- 5; }main(){int myvar;myvar = 3;call_me(myvar);printf("%d ",myvar);What will be printed a) 3 b) 5 c) 8 d) symbol
What is ctrl c called?