The task, in general, is fundamental, but the question my question grows from the origins of olympiad programming, where speed is a key resource. That there were no problems in the clarity of the wording, I will attach the link. Here is [1] ( http://acm.timus.ru/problem.aspx?space=1&num=1992 )!
But in short, that is, an object to which you can add something and remove the same thing (roll back to the old version, older content), and then, similarly, restore rollbacks. But the most important thing is that you can clone an object with its entire rollback history and current state. This is where the question comes up: how to implement cloning in the most optimal way?
Of course, the simplest solution is simply full cloning ( .clone()
, in java) with the implementation of the Cloneable
or similar interface. After that, we will have two independent entities with which to work; The critical drawback is the amount of memory consumed and time, of course. There are ideas on how to improve and optimize the usual two-stack idea; or what alternative?
Thank!