← Back to STL Containers
Question 524
Browser History
Browser History
Build a classBrowserHistorythat models the back and forward buttons of a web browser using two stacks. The browser starts on the pagehome. Implement these public methods: 1.void visit(const string& url)— pushes the current page onto the back stack, makesurlthe current page, and clears the forward stack 2.string back()— if the back stack is empty, returnNo historyand 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, returnNo forwardand 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 onhome, aftervisit("a.com")andvisit("b.com")the test printsback(),forward()andforward()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
Sign in to use hintsTopics:
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.