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
Is c++ a float?
What are pointer-to-members in C++? Give their syntax.
Evaluate the following expression as C++ would do :8 * 9 + 2 * 5 a) 82 b) 79 c) 370 d) list
Can I make ios apps with c++?
How we can differentiate between a pre and post increment operators during overloading?
What is the full form of ios?
Assume studentNames and studentIDs are two parallel arrays of size N that hold student data. Write a pseudocode algorithm that sorts studentIDs array in ascending ID number order such that the two arrays remain parallel.
Explain the isa and hasa class relationships.
Explain the difference between overloading and overriding?
What is the latest version on c++?
What is the difference between a type-specific template friend class and a general template friend class?
Differentiate between declaration and definition.
How can you differentiate between inheritance and implementation in c++?
What does n mean in c++?
What is the keyword auto for?