classBrowserHistory{privateclassNode{Node prev;Node next;String url;publicNode(String url){this.url = url;
prev =null;
next =null;}}Node cur;publicBrowserHistory(String homepage){
cur =newNode(homepage);}publicvoidvisit(String url){// add the new url
cur.next =newNode(url);// Assign the new node's prev node to the current one
cur.next.prev = cur;// Move the pointer to the latest node
cur = cur.next;}publicStringback(int steps){// Until the first element or the steps have exhuastedwhile(cur.prev !=null&& steps >0){
cur = cur.prev;--steps;}return cur.url;}publicStringforward(int steps){// Until the end or the steps have exhuastedwhile(cur.next !=null&& steps >0){
cur = cur.next;--steps;}return cur.url;}}