Stack can be said to be a special linked list. Its main feature is its advanced post-release mechanism, which is an important data structure and is widely used in our programming, for example, polynomial evaluation, balanced input and method call.
ImplementationCodeAs follows:
Package COM. suznhenxing; public class Stack {private int Top =-1; // stack top pointer private object [] items; // Private int size = 0 for data in the stack; private int capacity = 10; Public stack () {items = new object [capacity];} public object POP () {object o = NULL; If (top>-1) {o = items [Top]; size --; top --;} return O;} public void push (Object O) {// If (capacity = size) {capacity * = 2; // resize object [] newitems = new object [capacity]; for (INT I = 0; I <size; I ++) {newitems [I] = items [I];} items = newitems ;} items [top + 1] = O; size ++; top ++;} public int size () {return size ;}}