Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- class Memento {
- friend class CustomVector;
- private:
- std::vector<int> state;
- Memento(const std::vector<int>& vec) : state(vec) {}
- };
- class CustomVector {
- private:
- std::vector<int> data;
- public:
- void PushBack(int value) {
- data.push_back(value);
- }
- void PopBack() {
- if (!data.empty()) {
- data.pop_back();
- }
- }
- void Set(int index, int value) {
- if (index >= 0 && index < data.size()) {
- data[index] = value;
- }
- }
- int Get(int index) const {
- if (index >= 0 && index < data.size()) {
- return data[index];
- }
- return -1;
- }
- Memento CreateMemento() {
- return Memento(data);
- }
- void Restore(const Memento& memento) {
- data = memento.state;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement