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
How can I dynamically allocate arrays?
Explain the difference between strcpy() and memcpy() function?
#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }
What is the difference between char array and char pointer?
Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?
illustrate the use of address operator and dereferencing operator with the help of a program guys plzzz help for this question
What is function prototype in c language?
What is pointer to pointer in c?
What is the description for syntax errors?
What are pointers? What are different types of pointers?
Difference between linking and loading?
Can you think of a logic behind the game minesweeper.
What is difference between function overloading and operator overloading?
What is the scope of static variable in c?
Write a program to check armstrong number in c?