双端栈:有两个结点(左结点和右结点);左结点和右结点为空结点,开始时左结点的下一结点为右结点,右结点的下一结点为空,把左结点和右结点所处的位置当做栈顶,进行进栈,弹栈,查看当前栈顶元素等。
stack接口
/*
线性表的一种特殊情况
ArrayStack extends ArrayList
ArrayList当作ArrayStack的成员变量,对成员变量进行操作
*/
public interface Stack<E> extends Iterable<E>{
int getSize();
boolean isEmpty();
void push(E e);
E pop(); //弹栈一个元素并返回
E peek(); //查看当前栈顶
void clear(); //清空栈
}
双端栈
import DS01.动态数组.ArrayList;
import java.util.Iterator;
public class LinkedStackDoubleEnd<E> implements Stack<E> {
private Node left; //左结点
private Node right; //右结点
private int leftSize;
private int rightSize;
private class Node{
//结点内部类
E data;
Node next;
Node(){
this(null,null);
}
Node(E data,Node next){
this.data=data;
this.next=next;
}
public String toString(