Write BrowserHistory. The browser starts on home. Commands until the end of input:
visit PAGE— the current page goes on the back stack, and the forward stack is cleared;back— the current page goes on the forward stack and the top of the back stack becomes current (cannot go backif empty);forward— the reverse (cannot go forward);- anything else prints
unknown command ….
After each successful command print the page and both stack sizes; at the end print the current page and the back stack.
For the input
visit news visit mail back back back forward visit shop forward
the program prints
visit -> news (back 1, forward 0)
visit -> mail (back 2, forward 0)
back -> news (back 1, forward 1)
back -> home (back 0, forward 2)
cannot go back
forward -> news (back 1, forward 1)
visit -> shop (back 2, forward 0)
cannot go forward
Now on: shop
Back stack (top first): [news, home]