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


Please Help Members By Posting Answers For Below Questions

How can I dynamically allocate arrays?

594


Explain the difference between strcpy() and memcpy() function?

596


#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); }

784


What is the difference between char array and char pointer?

527


Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?

2123






illustrate the use of address operator and dereferencing operator with the help of a program guys plzzz help for this question

1586


What is function prototype in c language?

617


What is pointer to pointer in c?

635


What is the description for syntax errors?

616


What are pointers? What are different types of pointers?

632


Difference between linking and loading?

696


Can you think of a logic behind the game minesweeper.

2011


What is difference between function overloading and operator overloading?

661


What is the scope of static variable in c?

537


Write a program to check armstrong number in c?

635