sec stacks /*stack adt *public interface stack /*reinitialize the stack the user is responsible for reclaiming the storage used by the stack elements *public void clear()/*push an element onto the top of the stack @param it the element being pushed onto the stack *public void push( it)/*remove and return the element at the top of the stack @return the element at the top of the stack *public pop()/*@return copy of the top element *public topvalue()/*@return the number of elements in the stack *public int length()}figure the stack adt the array-based stack implementation is essentially simplified version of the array-based list the only important design decision to be made is which end of the array should represent the top of the stack one choice is to make the top be at position in the array in terms of list functionsall insert and remove operations would then be on the element in position this implementation is inefficientbecause now every push or pop operation will require that all elements currently in the stack be shifted one position in the arrayfor cost of th(nif there are elements the other choice is have the top element be at position when there are elements in the stack in other wordsas elements are pushed onto the stackthey are appended to the tail of the list method pop removes the tail element in this casethe cost for each push or pop operation is only th( for the implementation of figure top is defined to be the array index of the first free position in the stack thusan empty stack has top set to the first available free position in the array (alternativelytop could have been defined to be the index for the top element in the stackrather than the first free position if this had been donethe empty list would initialize top as - methods push and pop simply place an element intoor remove an element fromthe array position indicated by top because top is assumed to be at the first free positionpush first inserts its value into the top position and then increments topwhile pop first decrements top and then removes the top element