Java use dual LinkedList
I cannot think of a better data structure than dual-linked list to solve this problem.\nLooks like DDL is born to solve it.\n\n\nclass BrowserHistory {\n    \n 
I cannot think of a better data structure than dual-linked list to solve this problem.\nLooks like DDL is born to solve it.\n\n```\nclass BrowserHistory {\n    \n    public class Node{\n        String url;\n        Node next, prev;\n        public Node(String url) {\n            this.url = url;\n            next = null;\n            prev = null;\n        }\n    }\n    \n    Node curr;\n    public BrowserHistory(String homepage) {\n        curr = new Node(homepage);\n    }\n    \n    public void visit(String url) {\n        Node node = new Node(url);\n        curr.next = node;\n        node.prev = curr;\n        curr = node;\n    }\n    \n    public String back(int steps) {\n        while (curr.prev != null && steps-- > 0) {\n            curr = curr.prev;\n        }\n        return curr.url;\n    }\n    \n    public String forward(int steps) {\n        while (curr.next != null && steps-- > 0) {\n            curr = curr.next;\n        }\n        return curr.url;\n    }\n}\n```\nUpdate 20240108, removing unused "head", thanks to @gotit.
['Java']