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

Answer Posted / manesh nambiar

int return_fifth_from_end()
{
int i,j;
struct node *p,*q;
*p=HEAD_NODE;
for(i=0;i<4;i++)//will make p point to the 5th element
{
p=p->next;
if(p==NULL)
{
printf("List has less than 5 elements");
}
}
q=HEAD_NODE;
while(p!=NULL)
{
p=p->next;
q=q->next;
}
return(q->Value);
}

Is This Answer Correct ?    8 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is c called a structured programming language?

992


How can I change their mode to binary?

891


What is getch() function?

827


Why is it usually a bad idea to use gets()? Suggest a workaround.

1354


In a switch statement, explain what will happen if a break statement is omitted?

819


On most computers additional memory that is accessed through an adapter of feature card along with a device driver program. a) user memory b) conventional memory c) expandedmemory d) area

910


Can we declare function inside main?

755


write a program to print the consecutive repeated character from the given string... input string is : hhhhjkutskkkkkggggj output should be like this: hhhhkkkkkgggg anyone help me...

1704


Multiply an Integer Number by 2 Without Using Multiplication Operator

542


What is realloc in c?

815


c language supports bitwise operations, why a) 'c' language is system oriented b) 'c' language is problem oriented c) 'c' language is middle level language d) all the above

813


What language is lisp written in?

845


What are the restrictions of a modulus operator?

843


Why do we use stdio h and conio h?

841


Differentiate between calloc and malloc.

1004