用栈模拟浏览器c++

来源:互联网 发布:车牌识别软件破解版 编辑:程序博客网 时间:2024/06/05 16:34
#pragma   warning (disable: 4786)#include <iostream>#include <stack>#include <string>using namespace std;//要注意当前访问的页面就是backset栈顶的元素,切记//理解浏览器前进后退的含义自己编int main(){stack<string> back,forward;string command,url;back.push("http://www.acm.org/");while (cin>>command,command!="QUIT"){if (command == "VISIT"){cin>>url;back.push(url);cout<<url<<endl;    while(!forward.empty()) forward.pop();} else if (command == "BACK"){if (back.size()==1)//等于1表示就是当前的页面,已经不能够弹栈了{cout<<"Ignored"<<endl;} else{url = back.top();forward.push(url);back.pop();url = back.top();cout<<url<<endl;}}else if (command == "FORWARD"){if (forward.size()==0)//forward的大小可以为零,这点要与backset区分开来{cout<<"Ignored"<<endl;} else{url= forward.top();back.push(url);forward.pop();cout<<url<<endl;}}}return 0;}


 

原创粉丝点击