package bin;import java.util.ArrayList;import java.util.List;import org.omg.CORBA.SystemException;/** * @author bin * target 实现栈的顺序结构 * 摘要:栈 栈顶 栈底 LIFO 结构 last In First Out */public class Bin_stack { private int StackSize; private int current; private List list; public int getStackSize() { return StackSize; } public void setStackSize(int stackSize) { StackSize = stackSize; } public int getCurrent() { return current; } public void setCurrent(int current) { this.current = current; } public List getList() { return list; } public void setList(List list) { this.list = list; } public Bin_stack(int size){ this.setList(new ArrayList<>()); this.setCurrent(0); this.setStackSize(size); } public void push(Object o){ if(this.current == this.StackSize){ throw new RuntimeException("栈满"); }else{ list.add(o); current = ++current; } } public Object pop(){ if(current == 0){ throw new RuntimeException("空栈"); } Object o = list.get(current-1); list.remove(current-1); current = --current; return o; } public static void main(String[] args) { Bin_stack b = new Bin_stack(4); b.push(123); b.push(43); System.out.println(b.pop()); System.out.println(b.pop()); b.push(4312); } }