chap listsstacksand queues /*array-based stack implementation *class astack implements stack private static final int defaultsize private int maxsizeprivate int topprivate [listarray/maximum size of stack /index for top object /array holding stack /constructors astack(this(defaultsize)@suppresswarnings("unchecked"/generic array allocation astack(int sizemaxsize sizetop listarray ( [])new object[size]/create listarray public void clear(top /reinitialize stack public void push( it/push "itonto stack assert top !maxsize "stack is full"listarray[top++itpublic pop(/pop top element assert top ! "stack is empty"return listarray[--top]public topvalue(/return top element assert top ! "stack is empty"return listarray[top- ]public int length(return top/return length figure array-based stack class implementation