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 is the difference between declaring a variable by constant keyword and #define ing that variable?
What is dynamic variable in c?
Write a program to find the biggest number of three numbers in c?
Is c compiled or interpreted?
What is the use of the function in c?
Where static variables are stored in memory in c?
Which one would you prefer - a macro or a function?
What are the types of bitwise operator?
Explain what is the difference between functions getch() and getche()?
what is a NULL Pointer? Whether it is same as an uninitialized pointer?
Where are some collections of useful code fragments and examples?
in linking some of os executables are linking name some of them
When should a type cast not be used?
What is difference between Structure and Unions?
What are inbuilt functions in c?