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


     

  • 相关阅读:
    HDU.2899.Strange fuction(牛顿迭代)
    BZOJ.3771.Triple(母函数 FFT 容斥)
    树的实现(2)
    树的练习
    死锁问题
    进程的三种状态
    线程的同步与实现
    进程间通信详解
    进程和线程以及它们的区别
    https协议
  • 原文地址:https://www.cnblogs.com/gitran/p/3644137.html
Copyright © 2011-2022 走看看