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
Assume the list is a circular one (implemented by pos%10).
So, when you are iterating, you are going round and round in
a circle. When you reach the end, you just have to go back
exactly 10 items. By going back here means accessing the
element 10 position prior to the current one, which is
implemented by (pos-10)%10
Since, it's a circular array as assumed, you have always
access it by doing pos%10 or (pos-10)%10.
NOTE: The value of pos has always been incremented and never
decremented or set to zero.
| Is This Answer Correct ? | 2 Yes | 2 No |
Post New Answer View All Answers
What is an adjust field format flag?
What is the use of bit fields in structure declaration?
What are advantages of c++?
Why the usage of pointers in C++ is not recommended ?
Does c++ support exception handling?
What is anonymous object in c++?
Why main function is special in c++?
Can user-defined object be declared as static data member of another class?
Is set c++?
How the memory management in vectors are being done. What happens when the heap memory is full, and how do you handle it ?
When must you use a pointer rather than a reference?
Incase of a function declaration, what is extern means?
Explain how the virtual base class is different from the conventional base classes of the opps.
What is srand c++?
Mention the storage classes in c++.