我是靠谱客的博主 无辜大米,这篇文章主要介绍栈的java写法,现在分享给大家,希望可以做个参考。


/**

 * Created by jinzhao.w on 2015/5/23.

 */

public class Stack {

    private int lenth;

    private int[] array;

    private int top;


    public Stack(int lenth) {

        this.lenth = lenth;

        this.array = new int[lenth];

        this.top = -1;

    }


    public void push(int value){

        array[++top]=value;

    }

    public  int pop(){

        return array[top--];

    }

    public static void main(String[] args) {

        Stack stack=new Stack(10);

        stack.push(1);

        stack.push(2);

        stack.push(3);

        stack.push(4);

        for (int i = 0; i <4 ; i++) {

            System.out.println(stack.pop());

        }

    }

}


转载于:https://my.oschina.net/u/1390040/blog/419247

最后

以上就是无辜大米最近收集整理的关于栈的java写法的全部内容,更多相关内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(81)

评论列表共有 0 条评论

立即
投稿
返回
顶部