Implement a function that returns the 5th element from the
end in a singly linked list of integers in one pass.

Answer Posted / a.eklare7

int fifth_element_last(node *head)
{
node *p;
int len=0;
p=head;
while(p->next!=NULL)
{
p=p->next;
len++;
}
p=head;
for(int i=1;i<=len-4;i++)
p=p->next;
return(p->data);
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the difference between null pointer and void pointer.

685


How can my program discover the complete pathname to the executable from which it was invoked?

677


Is it possible to pass an entire structure to functions?

570


What is far pointer in c?

827


What is anagram in c?

533






Write a program for Overriding.

708


Should a function contain a return statement if it does not return a value?

614


what is the difference between class and unio?

1883


What is the symbol indicated the c-preprocessor?

711


Can we declare variable anywhere in c?

559


A function can make the value of a variable available to another by a) declaring the variable as global variable b) Passing the variable as a parameter to the second function c) Either of the two methods in (A) and (B) d) binary stream

686


Explain the difference between ++u and u++?

659


What is the difference between exit() and _exit() function in c?

600


swap 2 numbers without using third variable?

676


how do you execute a c program in unix.

653