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
differentiate built-in functions and user – defined functions.
What are header files in c programming?
What is && in c programming?
Explain how can I manipulate strings of multibyte characters?
write a program fibonacci series and palindrome program in c
Why c language is called c?
#define PRINT(int) printf("int = %d ",int) main() {< BR> intx,y,z; x=03;y=02;z=01; PRINT(x^x); z<<=3;PRINT(x); y>>=3;PRINT(y); }
Tell me when would you use a pointer to a function?
An expression to whose value an operater is applied a) operand b) variable c) constant d) all of the above
How do you determine a file’s attributes?
What is the main difference between calloc () and malloc ()?
a value that does not change during program execution a) variabe b) argument c) parameter d) none
Is javascript based on c?
hi to every one .. how to view table pool after creating the pooled table? plz help me.. if any knows abt this ..
Explain what is #line used for?