⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stack.java

📁 Java样例程序集合:2D
💻 JAVA
字号:
import java.util.EmptyStackException;public class Stack implements Cloneable {    private Object[] items;    private int top = 0;    public Stack(int size) {			items = new Object[size];    }    public void push(Object item) {			items[top++] = item;    }    public Object pop() {      if (top == 0)          throw new EmptyStackException();      Object obj = items[--top];			items[top]=null;      return obj;    }    public boolean isEmpty() {      if (top == 0)         return true;      else         return false;    }        protected Stack clone() {      try {         Stack s = (Stack)super.clone(); // Clone the stack         s.items = (Object[]) items.clone(); // Clone the list				 s.top = top; // Clone the array index of the top         return s; // Return the clone      } catch (CloneNotSupportedException e) {         //This shouldn't happen because Stack is Cloneable         throw new InternalError();      }   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -