Implement a function that returns the 5th element from the
end in a singly linked list of integers in one pass.
Answer Posted / gbohrn
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->next!=NULL)
{
p=p->next;
q=q->next;
}
return(q->Value);
}
| Is This Answer Correct ? | 5 Yes | 6 No |
Post New Answer View All Answers
What does 1f stand for?
What is a structure in c language. how to initialise a structure in c?
What is string concatenation in c?
What are the types of variables in c?
If errno contains a nonzero number, is there an error?
Explain null pointer.
any limit on the number of functions that might be present in a C program a) max 35 functions b) max 50 functions c) no limit d) none of the above
What are the main characteristics of c language describe the structure of ac program?
Is there sort function in c?
Explain do array subscripts always start with zero?
What is the difference between char array and char pointer?
What is difference between arrays and pointers?
What is the correct declaration of main?
How many identifiers are there in c?
What is pivot in c?