zoukankan      html  css  js  c++  java
  • 8、如何实现浏览器的前进、后退操作?

    答案是:栈。

    使用数组实现一个栈

    /**
     * Created by **** on 2018/10/16.
     * 基于数组实现的顺序栈
     */
    public class ArrayStack {
        private String[] items;
        private int n;
        private int count;
    
        //数组初始化,申请一个大小为n的空间
        public ArrayStack(int n){
            this.items = new String[n];
            this.n = n;
            this.count = 0;
        }
    
        //入栈操作
        public boolean push(String item){
            if(count == n) return false;
            items[count] = item;
            ++count;
            return true;
        }
    
        //出栈操作
        public String pop(){
            if(count == 0) return null;
            String temple = items[count];
            --count;
            return temple;
        }
    }
  • 相关阅读:
    1434. Buses in Vasyuki 夜
    SAP
    目标
    组合数
    KM算法模板
    网络流
    CodeForces 43E
    B. Unsorting Array codeforces 127
    Colorful Rainbows 127
    C. Anagram codeforces
  • 原文地址:https://www.cnblogs.com/CherishZeng/p/9795937.html
Copyright © 2011-2022 走看看