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 / vivek

ListNodePtr* tenthListNodePtr = NULL; //Holds 10th last node

ListNodePtr* tempListNodePtr = firstNode;

int counter = 1;

//Advance the tempListNodePtr to 10th node from first //node.
while( (counter < 10) && (tempListNodePtr) )
{

tempListNodePtr = tempListNodePtr->nextNode;

++counter;
}

tenthListNodePtr = firstNode;

//Advance both the pointers. also check for cycle.
// Since two ptrs differ by 10, when last node is reached
//the result will be there.
while( (tempListNodePtr) && (tempListNodePtr != firstNode) )
{

tenthListNodePtr = tenthListNodePtr->nextNode;

tempListNodePtr = tempListNodePtr->nextNode;

}

Is This Answer Correct ?    14 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are static type checking?

1056


What is diamond problem in c++?

1002


What is constant in c++ with example?

1153


What are the uses of static class data?

1187


What do you understand by zombie objects in c++?

1102


Specify some guidelines that should be followed while overloading operators?

1209


What is #include iostream?

1255


In int main(int argc, char *argv[]) what is argv[0] a) The first argument passed into the program b) The program name c) You can't define main like that

1096


What does override mean in c++?

1066


Who was the creator of c++?

1053


What is polymorphism & list its types in c++?

1065


Differentiate between the message and method in c++?

1075


Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.

1329


Who made c++?

1088


What is endl?

1155