Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BrowserHistory {
- stack<string> forwa;
- stack<string> backward;
- string current;
- public:
- BrowserHistory(string homepage) {
- current = homepage;
- }
- void visit(string url) {
- backward = stack<string>();
- forwa.push(current);
- current = url;
- }
- string back(int steps) {
- for(int i=1;i<=steps && !forwa.empty();i++)
- {
- backward.push(current);
- current = forwa.top();
- forwa.pop();
- }
- return current;
- }
- string forward(int steps) {
- for(int i=1;i<=steps && !backward.empty();i++)
- {
- forwa.push(current);
- current = backward.top();
- backward.pop();
- }
- return current;
- }
- };
Advertisement