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

Write a function that will take in a phone number and output all possible alphabetical combinations

799


What is the c language function prototype?

843


Explain what is the benefit of using an enum rather than a #define constant?

972


why programs in c are running with out #include? some warnings are display in terminal but we execute the program we get answer why? eg: main() { printf("hello world "); }

1508


Explain what math functions are available for integers? For floating point?

833


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

1133


Do character constants represent numerical values?

1059


What is build process in c?

855


What are the advantages and disadvantages of c language?

755


plz let me know how to become a telecom protocol tester. thank you.

1953


What are linked lists in c?

836


What is the use of pragma in embedded c?

772


Describe the difference between = and == symbols in c programming?

1007


What is extern c used for?

743


hi any body pls give me company name interview conduct "c" language only

1877