Using Doubly Linked Lists || C++
Complexity\n- Time complexity:\nO(n) \n- Space complexity:\nO(n) \n# Code\n\nclass BrowserHistory {\n    \n    struct list{\n        string val;\n        struct
# Complexity\n- Time complexity:\n$$O(n)$$ \n- Space complexity:\n$$O(n)$$ \n# Code\n```\nclass BrowserHistory {\n    \n    struct list{\n        string val;\n        struct list *next, *pre;\n    };\n\npublic:\n    list *head;\n    BrowserHistory(string homepage) {\n        head = new(struct list);\n        head->val = homepage;\n        head->next = NULL;\n        head->pre = NULL;\n    }\n    \n    void visit(string url) {\n        // add a new node ie visiting a new site\n        list *newNode = new (list);\n        list *node = head->pre;\n\n        newNode->val = url;\n        newNode->next = head;\n        head->pre = newNode;\n        newNode->pre = NULL;\n        head = newNode;\n    }\n    \n    string back(int steps) {\n        // going to the next node for steps number of times\n        while(head->next && steps)\n        {\n            head = head->next;\n            steps--;\n        }\n        return head->val;\n    }\n    \n    string forward(int steps) {\n        // going to the pre node for steps number of times\n        while(head->pre and steps)\n        {\n            head = head->pre;\n            steps--;\n        }\n        return head->val;\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```
['C++']