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

Answer Posted / manesh nambiar

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!=NULL)
{
p=p->next;
q=q->next;
}
return(q->Value);
}

Is This Answer Correct ?    8 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is meant by keywords in c?

620


Explain what is meant by 'bit masking'?

646


How can you increase the allowable number of simultaneously open files?

599


Define recursion in c.

704


4. main() { int c=- -2; printf("c=%d",c); }

1373






Explain how can I open a file so that other programs can update it at the same time?

596


Explain how can you tell whether two strings are the same?

587


What is a rvalue?

755


main() { struct s1 { char *str; struct s1 *ptr; }; static struct s1 arr[] = { {"Hyderabad",arr+1}, {"Bangalore",arr+2}, {"Delhi",arr} }; struct s1 *p[3]; int i; < BR> for(i=0;i<=2;i++) p[i] = arr[i].ptr; printf("%s ",(*p)->str); printf("%s ",(++*p)->str); printf("%s ",((*p)++)->str); }

923


Differentiate between the expression “++a” and “a++”?

709


What are different types of pointers?

566


Explain what are linked list?

628


What is malloc() function?

638


What is volatile keyword in c?

587


How can I implement a delay, or time a users response, with sub-second resolution?

630