Two stacks to simulate the operation of the browser, a simple simulation.
1#include <iostream>2#include <string>3#include <stack>4 using namespacestd;5 6stack<string>forward;7stack<string>Back ;8 9 intMain ()Ten { One stringCur"http://www.acm.org/"), TMP; A while(Cin >>tmp) - { - if(TMP = ="QUIT" ) the { - Break; - } - Else if(TMP = =" Back" ) + { - if(Back.empty ()) + { Acout <<"ignored"<<Endl; at } - Else - { - Forward.push (cur); -Cur =back.top (); - Back.pop (); incout << cur <<Endl; - } to } + Else if(TMP = ="FORWARD" ) - { the if(Forward.empty ()) * { $cout <<"ignored"<<Endl;Panax Notoginseng } - Else the { + Back.push (cur); ACur =forward.top (); the Forward.pop (); +cout << cur <<Endl; - } $ } $ Else if(TMP = ="VISIT" ) - { - Back.push (cur); theCIN >>cur; - while( !forward.empty ())Wuyi { the Forward.pop (); - } Wucout << cur <<Endl; - } About } $ return 0; -}
Application of Toj 1196 stack (simulated browser)