题意:实现网页访问,前进,后退的功能
思路:开两个stack进行模拟栈操作 画两个栈,写写就知道怎么回事了
#include<iostream>
#include<string>
#include<stack>
using namespace std;
int main()
{
stack<string> F;
stack<string> B;
string a,b;
B.push("http://www.acm.org/");
while(cin>>a)
{
if(a=="QUIT") break;
else if(a=="VISIT")
{
cin>>b;
cout<<b<<endl;
B.push(b);
while(!F.empty())
F.pop();
}
else if(a=="BACK")
{
if(B.size()>1)
{
F.push(B.top());
B.pop();
cout<<B.top()<<endl;
}
else
cout<<"Ignored"<<endl;
}
else if(a=="FORWARD")
{
if(F.size())
{
cout<<F.top()<<endl;
B.push(F.top());
F.pop();
}
else
cout<<"Ignored"<<endl;
}
}
}