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
why and when we can declar member fuction as a private in the class?
Differentiate between C and C++.
Define namespace in c++?
What language does google use?
What is the full form of dos?
Why do we need templates?
Do you know what are static and dynamic type checking?
Can you pass an array to a function in c++?
Is it possible to get the source code back from binary file?
What does getch() do according to the ANSI C++ standard a) Reads in a character b) Checks the keyboard buffer c) Nothing in particular (Its not defined there)
What is the use of 'this' pointer?
What is the full form of ios?
What are all predefined data types in c++?
Do you know about latest advancements in C++ ?
What do you mean by const correctness?