C++ - 2 solutions - Using Stacks & Doubly Linked List
 # Intuition  \n\n\n\n\n# Using 2 Stacks \n# Complexity\n- Time complexity:O(n)\n\n\n- Space complexity:O(n)\n\n\n# Code\nC++ []\nclass BrowserHistory {\npublic
<!-- # Intuition -->\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n<!-- # Approach -->\n<!-- Describe your approach to solving the problem. -->\n# *Using 2 Stacks* \n# Complexity\n- Time complexity:$$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```C++ []\nclass BrowserHistory {\npublic:\n    stack<string> history ;\n    stack<string> future ;\n    \n    BrowserHistory(string homepage) {\n        history.push(homepage) ;\n        future = stack<string>() ;\n    }\n    \n    void visit(string url) {\n        history.push(url) ;\n        future = stack<string>() ;\n    }\n    \n    string back(int steps) {\n        while(steps > 0 && history.size() > 1)\n        {\n            future.push(history.top()) ;\n            history.pop() ;\n            steps -- ;\n        }\n        return history.top() ;\n    }\n    \n    string forward(int steps) {\n        while(steps>0 && future.size()>0)\n        {\n            history.push(future.top()) ;\n            future.pop() ;\n            steps -- ;\n        }\n        return history.top() ; \n    }\n};\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * BrowserHistory* obj = new BrowserHistory(homepage);\n * obj->visit(url);\n * string param_2 = obj->back(steps);\n * string param_3 = obj->forward(steps);\n */\n```\n---\n# *Using Doubly Linked List* [Fastest Solution]\n# Complexity\n- Time complexity:$$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```C++ []\nclass BrowserHistory {\npublic:\n// Using Doubly Linked List\nclass node{\n    private:\n    public:\n    node *next ;\n    node *prev ; \n    string url ; \n\n    node (string url)\n    {\n        this -> url = url ; \n        this -> next = NULL ; \n        this -> prev = NULL ; \n    }\n};\nnode *curr ; \n\n    BrowserHistory(string homepage) {\n        curr = new node(homepage) ; \n    }\n    \n    void visit(string url) {\n        node *temp = new node (url) ; \n        curr -> next = temp ; \n        temp -> prev = curr ; \n        curr = curr -> next  ;\n    }\n    \n    string back(int steps) {\n        while (curr -> prev != NULL && steps -- > 0)\n        {\n            curr = curr -> prev ; \n        }\n        return curr -> url ; \n    }\n    \n    string forward(int steps) {\n        while (curr -> next != NULL && steps -- > 0)\n        {\n            curr = curr -> next ; \n        }\n        return curr -> url ; \n    }\n};\n\n/**\n * Your BrowserHistory object will be instantiated and called as such:\n * BrowserHistory* obj = new BrowserHistory(homepage);\n * obj->visit(url);\n * string param_2 = obj->back(steps);\n * string param_3 = obj->forward(steps);\n */\n```\n![815a317f-9cdf-46e2-a397-af8869dafa2e_1673498197.3721023.png](https://assets.leetcode.com/users/images/b7720b62-3936-44f7-983d-f3fb6924582a_1679155365.0774841.png)\n
['Linked List', 'Stack', 'Data Stream', 'C++']