C++ | Doubly Linked List | Easy-to-understand | 100ms
\nclass BrowserHistory {\npublic:\n    list<string> historyPages;  // the pages that are present in my browser history\n    list<string> :: iterator it;\n    Br
```\nclass BrowserHistory {\npublic:\n    list<string> historyPages;  // the pages that are present in my browser history\n    list<string> :: iterator it;\n    BrowserHistory(string homepage) {\n        historyPages.emplace_back(homepage);\n        it = historyPages.begin();\n    }\n    \n    void visit(string url) {\n        auto del = it; \n        del++;  // delete the history: (here, last]\n        historyPages.erase(del, historyPages.end()); \n        historyPages.emplace_back(url);  // add a new page after here\n        it++;  \n    }\n    \n    string back(int steps) {  // at most we can reach start of list\n        while(it != historyPages.begin() && steps--) it--;\n        return *it;  // return value by dereferencing the pointer/iterator\n    }\n    \n    string forward(int steps) {  // at most we can reach the end of list\n        while(it != (--historyPages.end()) && steps--) it++;\n        return *it;\n    }\n};\n```\n\nAn upvote would be appreciated. ^_^
['Linked List', 'C', 'C++']