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


Please Help Members By Posting Answers For Below Questions

Is c++ primer good for beginners?

593


How do you write a function that can reverse a linked-list?

576


What are c++ data types?

646


Is it possible to pass an object of the same class in place of object reference to the copy constructor?

572


Does improper inheritance have a potential to wreck a project?

634






Does dev c++ support c++ 11?

556


Can manipulators fall in love?

568


Is it possible for the objects to read and write themselves?

651


Can recursive program be written in C++?

635


How does atoi function work?

628


What can I use instead of namespace std?

645


Difference between overloading vs. Overriding

594


What is ostream in c++?

578


What is conditions when using boolean operators?

607


Does c++ have string data type?

695