Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / abhijit annaldas

node* getNthFromLast(node* head, int n)
{
int c;
node *nth;
while(pt!=NULL)
{
pt=pt->next;
c++;
if(c>=n)
*nth=pt;
}
if(c<n) //LL contains less than n nodes
return (*node)0;
else
return *nth;
}

Use it as..
fifth_node = getNthFromLast(head, 5);

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a sequential access file?

1169


How do you generate random numbers in C?

1193


Why C language is a procedural language?

1021


what is recursion in C

1060


Explain what are header files and explain what are its uses in c programming?

1153


What does dm mean sexually?

1301


Is c still relevant?

1076


write a c program to print the next of a particular no without using the arithmetic operator or looping statements?

3950


Explain low-order bytes.

1030


When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?

1063


Explain how do you search data in a data file using random access method?

1132


What are multidimensional arrays?

1116


What is the return type of sizeof?

1063


What are the advantages of c language?

1091


Can variables be declared anywhere in c?

1085