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
What is meant by keywords in c?
Explain what is meant by 'bit masking'?
How can you increase the allowable number of simultaneously open files?
Define recursion in c.
4. main() { int c=- -2; printf("c=%d",c); }
Explain how can I open a file so that other programs can update it at the same time?
Explain how can you tell whether two strings are the same?
What is a rvalue?
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); }
Differentiate between the expression “++a” and “a++”?
What are different types of pointers?
Explain what are linked list?
What is malloc() function?
What is volatile keyword in c?
How can I implement a delay, or time a users response, with sub-second resolution?