CJCoding With Joseph
15free / daySign inCreate account

Browser History

Build a class BrowserHistory that models the back and forward buttons of a web browser using two stacks. The browser starts on the page home.

Implement these public methods:
1. void visit(const string& url) — pushes the current page onto the back stack, makes url the current page, and clears the forward stack
2. string back() — if the back stack is empty, return No history and change nothing; otherwise push the current page onto the forward stack, pop the back stack into the current page, and return it
3. string forward() — if the forward stack is empty, return No forward and change nothing; otherwise push the current page onto the back stack, pop the forward stack into the current page, and return it
4. string current() const — returns the current page

Example: starting on home, after visit("a.com") and visit("b.com") the test prints back(), forward() and forward() again, one per line (see Expected Output).

Do NOT write a main function.

Expected Output:

a.com
b.com
No forward
home
No history
x.com
No forward
x.com
home
No history
home

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
STL ContainersStacks
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.