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...

Memory is not a constraint. In a single iteration(NOTE: you
can't go back), how will you find out the 10th last
node/item in a linked list.

Answer Posted / ashutosh

List *nodes[10]; //asked 10th last, so, only 10 items
int pos = 0;

List *ptr = &FirstNode

while(ptr)
{
nodes[(pos%10)] = ptr;
pos++;
ptr = ptr->next;
}
if(pos>=10)
{
printf("Tenth last element is %d",nodes[(pos-10)%10]->data);
}
else
{
printf("There doesn't exist any 1oth last element");
}

Is This Answer Correct ?    13 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can class objects be passed as function arguments?

1082


I want explanation for this assignment: how to connect mysql database using c/c++,please explain this detailly?

2088


Name four predefined macros.

1053


What are separators in c++?

1100


Is c++ pass by reference or value?

1087


Are strings immutable in c++?

1170


What is the difference between method overloading and method overriding in c++?

1162


Difference between a homogeneous and a heterogeneous container

1157


Explain about vectors in c ++?

1042


Can we declare a base-class destructor as virtual?

1022


If a header file is included twice by mistake in the program, will it give any error?

1068


What you know about structures in C++?

1102


What is a list c++?

1116


What are the important differences between c++ and java?

1163


What is ostream in c++?

1026