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

Answer Posted / a.eklare7

int fifth_element_last(node *head)
{
node *p;
int len=0;
p=head;
while(p->next!=NULL)
{
p=p->next;
len++;
}
p=head;
for(int i=1;i<=len-4;i++)
p=p->next;
return(p->data);
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is the basis for selection of arrays or pointers as data structure in a program

3793


What is the meaning of typedef struct in c?

602


Do array subscripts always start with zero?

788


Write a program to check palindrome number in c programming?

604


What is difference between %d and %i in c?

698






What does %d do in c?

552


What is the purpose of macro in C language?

670


What are derived data types in c?

618


Explain what are global variables and explain how do you declare them?

645


1.int a=10; 2.int b=20; 3. //write here 4.b=30; Write code at line 3 so that when the value of b is changed variable a should automatically change with same value as b. 5.

1670


How can I find out how much free space is available on disk?

634


What is chain pointer in c?

607


Why doesnt this code work?

622


hello freinds next week my interview in reliance,nybody has an idea about it intervew questions..so tell

1677


Can a program have two main functions?

577