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

Does c have class?

1051


What is queue in c?

1034


How do I get a null pointer in my programs?

1060


What is the use of getch ()?

1037


Why isnt there a numbered, multi-level break statement to break out

994


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

1062


What is context in c?

884


Which is better between malloc and calloc?

1120


What are the types of data types and explain?

1035


How can I direct output to the printer?

1272


Why c language?

1006


An integer that indentifies the position of a data item in a sequence of data items a) value b) number c) index d) all of the above

1152


How we can insert comments in a c program?

1070


int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;

1729


how to introdu5ce my self in serco

1938