/**
* 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写法的全部内容,更多相关栈内容请搜索靠谱客的其他文章。
发表评论 取消回复