zoukankan      html  css  js  c++  java
  • package com.fxr.stack;
    
    /**
     * Created by airycode on 2017/3/12.
     */
    public class MyStack {
        private long [] arr;
        private int top;
    
        /**
         *默认的构造方法
         */
        public MyStack(){
            arr = new long[10];
            top = -1;
        }
        /**
         * 带参数的构造方法
         */
        public MyStack(int maxSize){
            arr = new long[maxSize];
            top = -1;
        }
    
        //添加数据
        public void push(long value){
            arr[++top] = value;
        }
        //删除数据
        public long pop(){
            return arr[top--];
        }
        //查看数据
        public long peek(){
            return arr[top];
        }
        //判断是不是为空
        public boolean isEmpty(){
            return top == -1;
        }
        //判断是不是满
        public boolean isFull(){
            return top == arr.length-1;
        }
    
    }
    
    
    ------------------------------------------------------------------------------------------------
    package com.fxr.stack;
    
    /**
     * Created by airycode on 2017/3/12.
     */
    public class TestMyStack {
    
        public static void main(String[] args){
            MyStack myStack = new MyStack(4);
            myStack.push(1);
            myStack.push(2);
            myStack.push(3);
            myStack.push(4);
    
            System.out.println(myStack.isEmpty());
            System.out.println(myStack.isFull());
            System.out.println(myStack.peek());
    
        }
    
    }
    

      

  • 相关阅读:
    UPC2018组队训练赛第二场
    杭电多校训练第十场
    socks5 代理
    windows pip 报错Unable to find vcvarsall.bat
    emacs笔记
    homestead oci8
    pyenv install
    chrome 设置sock5代理
    laravel 接收post json
    laravel 使用已有数据库自动创建model
  • 原文地址:https://www.cnblogs.com/airycode/p/6537981.html
Copyright © 2011-2022 走看看