zoukankan      html  css  js  c++  java
  • 用栈模拟浏览器c++

    #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;
    }
    


     

  • 相关阅读:
    TASK1
    CSS再学
    Html再学
    Python的hasattr() getattr() setattr() 函数使用方法详解
    GET/POST/g和钩子函数(hook)
    cookie和session
    SQLAlchemy外键的使用
    jquery树形菜单插件treeView
    linux设置防火墙
    linux解压命令
  • 原文地址:https://www.cnblogs.com/gitran/p/3644137.html
Copyright © 2011-2022 走看看