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
Why clrscr is used in c?
What do you know about the use of bit field?
List the difference between a 'copy constructor' and a 'assignment operator' in C?
Can we declare a function inside a function in c?
What is a const pointer in c?
How can you read a directory in a C program?
What is difference between structure and union with example?
What is clrscr ()?
How many main () function we can have in a project?
Why is sizeof () an operator and not a function?
What is difference between stdio h and conio h?
The file stdio.h, what does it contain?
Explain high-order bytes.
In a switch statement, explain what will happen if a break statement is omitted?
What is indirection? How many levels of pointers can you have?