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 is type of 'this' pointer? Explain when it is get created?

1064


What are references in c++? What is a local reference?

1104


What is the difference between map and hashmap in c++?

1157


Is set c++?

1046


Is swift better than c++?

988


What are the benefits of operator overloading?

1269


How const int *ourpointer differs from int const *ourpointer?

1185


What is else syntax in c++?

1261


Can I run c program in turbo c++?

1080


What is data binding in c++?

1004


Perform addition, multiplication, subtraction of 2-D array using Operator Overloading.

3936


Write a program to find the Factorial of a number

1117


Explain pass by value and pass by reference.

1102


What is a character in c++?

1087


Can we define a constructor as virtual in c++?

1182