class BrowserHistory {
public:
int index;
vector<string> list;
BrowserHistory(string homepage) {
index = 0;
list = {homepage};
}
void visit(string url) {
while(index+1 != list.size()) {
list.pop_back();
}
++index;
list.emplace_back(url);
}
string back(int steps) {
index = max(0, index - steps);
return list[index];
}
string forward(int steps) {
index = min((int)list.size() - 1, index + steps);
return list[index];
}
};
/**
* Your BrowserHistory object will be instantiated and called as such:
* Your BrowserHistory object will be instantiated and called as such:
* BrowserHistory* obj = new BrowserHistory(homepage);
* BrowserHistory* obj = new BrowserHistory(homepage);
* obj->visit(url);
* obj->visit(url);
* string param_2 = obj->back(steps);
* string param_2 = obj->back(steps);
* string param_3 = obj->forward(steps);
* string param_3 = obj->forward(steps);
*/
*/