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
Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
What is integer constants?
The postoder traversal is 7,14,3,55,22,5,17 Then ur Inorder traversal is??? please help me on this
What is main () in c language?
What is typedef?
Why pointers are used in c?
What does #pragma once mean?
What are the loops in c?
What is the behavioral difference when include header file in double quotes (“”) and angular braces (<>)?
What are structure members?
hi send me sample aptitude papers of cts?
What does sizeof return c?
What is the purpose of ftell?
Hai,I have done with my bachelor of commerce and planing to ms,please suggest me how to convince vo for shifting from commerce to computers. Visa on 8 DEC 2014 Npu university
What is the advantage of using #define to declare a constant?