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

Answer Posted / tarun dhiraj

Consider:
struct Node
{
int data;
struct Node *next;
}*start;

void FIFTHFRMLAST()
{
struct Node *ptr;
ptr=start;

printf("\n");

/*Traverse elements of linked list till the 5th element from
the end of linked list*/
while(ptr->next->next->next->next->next!=NULL)
{
ptr=ptr->next;
}
printf("->%d",ptr->data);

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the different file extensions involved when programming in C?

987


what is different between auto and local static? why should we use local static?

853


What type is sizeof?

776


What is s or c?

775


What is difference between arrays and pointers?

746






Calculate the weighted average of a list of n numbers using the formula xavg = f1x1+f2x2+ ….+ fnxn where the f’s are fractional weighting factors, i.e., 0<=fi<1, and f1+f2+….+fn = 1

3918


What is huge pointer in c?

751


How do you use a pointer to a function?

832


Write a program to display all the prime nos from 1 to 1000000, your code should not take time more than a minute to display all the nos.

1770


A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor

828


What is a string?

840


What are the advantages of c language?

834


disply the following menu 1.Disply 2.Copy 3.Append; as per the menu do the file operations 4.Exit

1820


What are global variables?

845


What is the difference between #include

and #include “header file”?

755