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
Write a program to swap two numbers without using the third variable?
Why is c used in embedded systems?
How can I pad a string to a known length?
what is uses of .net
What is string function c?
What is difference between arrays and pointers?
What are variables c?
What is the use of linkage in c language?
Why isn't it being handled properly?
What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?
What is signed and unsigned?
can any one provide me the notes of data structure for ignou cs-62 paper
What is a const pointer?
Explain what is wrong with this statement? Myname = ?robin?;
How do I create a directory? How do I remove a directory (and its contents)?