Java之栈结构
作者:互联网
import java.util.ArrayList;
import java.util.List;
public class StackNow {
private List stack;
public StackNow(){
this.stack=new ArrayList();
}
//入栈
public void plush(Object object){
stack.add(object);
}
//弹栈
public Object pop(){
Object o = stack.get(stack.size() - 1);
stack.remove(stack.size() - 1);
return o;
}
public static void main(String[] args) {
StackNow stackNow=new StackNow();
String a="12321";
Integer b=123;
Double c=213.2;
String d="你好啊";
stackNow.plush(a);
stackNow.plush(b);
stackNow.plush(c);
stackNow.plush(d);
Object pop = stackNow.pop();
System.out.println(pop);//你好啊
Object pop1 = stackNow.pop();
System.out.println(pop1);//213.2
}
}
标签:之栈,Java,stackNow,Object,pop,plush,public,stack,结构 来源: https://blog.csdn.net/weixin_44269674/article/details/114384773