✅ [C++] | Beginner Friendly Solutions | Stack & Doubly Linked List
Using Stack\n Time Complexity = O(N)\n Space Complexity = O(N) + O(N)\n\nclass BrowserHistory {\npublic:\n    stack<string> prev;\n    stack<string> next;\n\n  
##### Using Stack\n* Time Complexity = `O(N)`\n* Space Complexity = `O(N) + O(N)`\n```\nclass BrowserHistory {\npublic:\n    stack<string> prev;\n    stack<string> next;\n\n    BrowserHistory(string homepage) {\n        prev.push(homepage);\n    }\n    \n    void visit(string url) {\n        prev.push(url);\n        while(!next.empty()) next.pop();\n    }\n    \n    string back(int steps) {\n        string last;\n        while(steps-- && !prev.empty()) {\n            last = prev.top();\n            next.push(last);\n            prev.pop();\n        }\n\n        if(prev.empty()) {\n            prev.push(last);\n            next.pop();\n        }\n\n        return prev.top();\n    }\n    \n    string forward(int steps) {\n        string last;\n        while(steps-- && !next.empty()) {\n            last = next.top();\n            prev.push(last);\n            next.pop();\n        }\n\n        return prev.top();\n    }\n};\n```\n\n##### Using Doubly Linked List\n* Time Complexity = `O(N)`\n* Spcace Complexity = `O(N)`\n\n```\nclass Node {\npublic:\n    string str;\n    Node* prev;\n    Node* next;\n\n    Node(string data) {\n        str = data;\n        prev = nullptr;\n        next = nullptr;\n    }\n};\n\nclass BrowserHistory {\npublic:\n    Node* curr;\n\n    BrowserHistory(string homepage) {\n        curr = new Node(homepage);\n    }\n    \n    void visit(string url) {\n        Node* newNode = new Node(url);\n        newNode -> prev = curr;\n        curr -> next = newNode;\n        curr = newNode;\n    }\n    \n    string back(int steps) {\n        while(steps-- && curr->prev) {\n            curr = curr->prev;\n        }\n        return curr->str;\n    }\n    \n    string forward(int steps) {\n        while(steps-- && curr -> next) {\n            curr = curr -> next;\n        }\n        return curr -> str;\n    }\n};\n```\n
['C++']