package sort;
import java.util.ArrayDeque;
import java.util.Deque;
public class MyStack<E> {
//容器
private Deque<E> container=new ArrayDeque<E>();
//容量
private int cap;
public MyStack(int cap){
super();
this.cap=cap;
}
//压站
public boolean push(E e){
if(this.container.size()+1>this.cap){
return false;
}
return this.container.offerLast(e);
}
//弹站
public E pop(){
return this.container.pollLast();
}
//出战
public E peak(){
return this.container.peekLast();
}
public int size(){
return this.container.size();
}
public static void main(String[] args) {
MyStack<String> stack=new MyStack<String>(10);
stack.push("a");
stack.push("b");
System.out.println(stack.pop());
System.out.println(stack.pop());
}
}
最后
以上就是欢喜菠萝最近收集整理的关于ArrayDeque实现栈的全部内容,更多相关ArrayDeque实现栈内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复