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 it possible to provide special behavior for one instance of a template but not for other instances?

827


What are features of c++?

828


What is c++ library?

793


What operator is used to access a struct through a pointer a) >> b) -> c) *

836


what is data encapsulation in C++?

794


What is the two main roles of operating system?

720


How do you import payscale data from non SAP to SAP?is it through LSMW or any other way is there?

3401


an operation between an integer and real always yeilds a) integer result b) real result c) float result

933


What is a constructor and how is it called?

785


What is std :: flush?

802


What is an adaptor class in c++?

782


Does a derived class inherit or doesn't inherit?

824


What is the difference between an enumeration and a set of pre-processor # defines?

1071


What is auto type c++?

842


What is main function in c++ with example?

806