File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ class ListNode {
2+ ListNode back ;
3+ String url ;
4+ ListNode forward ;
5+ public ListNode (String url ){
6+ this .url = url ;
7+ back = forward = null ;
8+ }
9+ }
10+
11+ class BrowserHistory {
12+
13+ ListNode head ;
14+ ListNode current ;
15+
16+ public BrowserHistory (String homepage ) {
17+ head = new ListNode (homepage );
18+ current = head ;
19+ }
20+
21+ public void visit (String url ) {
22+ current .forward = new ListNode (url );
23+ current .forward .back = current ;
24+ current = current .forward ;
25+ }
26+
27+ public String back (int steps ) {
28+ while (steps >0 && current .back !=null ){
29+ current = current .back ;
30+ steps --;
31+ }
32+ return current .url ;
33+ }
34+
35+ public String forward (int steps ) {
36+ while (steps >0 && current .forward !=null ){
37+ current = current .forward ;
38+ steps --;
39+ }
40+ return current .url ;
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments