Implement a function that returns the 5th element from the
end in a singly linked list of integers in one pass.

Answer Posted / amol b

int return_fifth_from_end()
{
int a[5],curr_ct=0;
struct node *p;
p=head;
while(p->next!=NULL)
{
a[curr_ct%5]=p->val;
p=p->next;
curr_ct++;
}
if(curr_ct>=5)
return a[(curr_ct-5)%5];
else
return -1;
}

Is This Answer Correct ?    8 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

‘ C’ PROGRAME TO SHOW THE TYPE OF TRANGLE BY ACCEPTING IT’S LENGTH .

2554


What is the difference between malloc() and calloc()?

992


What do you know about the use of bit field?

793


What is a constant and types of constants in c?

822


What does static variable mean in c?

831






What is the use of typedef in structure in c?

694


What are conditional operators in C?

792


Is c++ based on c?

821


What are dangling pointers? How are dangling pointers different from memory leaks?

891


How can I remove the trailing spaces from a string?

793


Write a program to print factorial of given number without using recursion?

760


How can I manipulate individual bits?

779


What is the scope of static variable in c?

702


List at least 10 sorting methods indicating their average case complexity, worst case complexity and best case complexity.

2484


What is "Duff's Device"?

885