-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDesign Browser History
More file actions
45 lines (41 loc) · 1.01 KB
/
Design Browser History
File metadata and controls
45 lines (41 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class BrowserHistory {
List<String> url = new ArrayList<>();
int ix = 0;
public BrowserHistory(String homepage) {
url.add(homepage);
}
public void visit(String url1) {
if(ix < url.size()-1){
for(int i = url.size()-1; i>ix; i--){
url.remove(i);
}
}
url.add(url1);
ix++;
}
public String back(int steps) {
if(ix - steps < 0){
ix = 0;
return url.get(ix);
}
else{
ix -= steps;
}
return url.get(ix);
}
public String forward(int steps) {
if(ix + steps >= url.size()){
ix = url.size()-1;
return url.get(ix);
}
ix += steps;
return url.get(ix);
}
}
/**
* Your BrowserHistory object will be instantiated and called as such:
* BrowserHistory obj = new BrowserHistory(homepage);
* obj.visit(url);
* String param_2 = obj.back(steps);
* String param_3 = obj.forward(steps);
*/