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
general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only
What is a structure member in c?
What is advantage of pointer in c?
how to count no of words,characters,lines in a paragraph.
Explain how do you convert strings to numbers in c?
What is bss in c?
What is wrong with this declaration?
How do you print only part of a string?
What are formal parameters?
What is a pointer value and address in c?
Using functions, write a program that multiplies two arrays. Use the following functions: - Function ReadArray - Function MultiplyArrays - Function DisplayArrays
What is pragma in c?
Explain what is wrong with this program statement? Void = 10;
What is the difference between malloc() and calloc()?
What is a substring in c?