JAVA Implementation Stack
Package linklist;/*** JAVA implements the data structure of the stack (Advanced and later) * use arrays to store * @ author zhang **/public class Stack {private Object [] stackElement; private int length = 16; private int size = 0; private int postion = 0; // cursor position public Stack () {} public Stack (int length) {this. length = length;}/*** determines if it is full * @ return */private boolean isFul () {if (postion = size) {return true ;} else {return false ;}}/*** if it is full, apply for a new space and copy the original space to the new space */private void copy () {Object ele [] = new Object [length + 16]; // each amplification of 16 for (int I = 0; I
= 0 & pos <= postion) {return stackElement [pos];} return null;}/*** traverse all */public void display () {for (int I = postion; I> 0; I --) {Object obj = pop (I); System. out. println (obj. toString () ;}} public static void main (String [] args) {Stack stack Stack = new Stack (); for (int I = 0; I <10; I ++) {stack. push (I);} stack. display ();}}