listing stacks and queues continued /end class stackapp ///////////////////////////////////////////////////////////////the main(method in the stackapp class creates stack that can hold itemspushes items onto the stackand then displays all the items by popping them off the stack until it' empty here' the output notice how the order of the data is reversed because the last item pushed is the first one poppedthe appears first in the output this version of the stackx class holds data elements of type long as noted in "simple sorting,you can change this to any other typeincluding object types stackx class methods the constructor creates new stack of size specified in its argument the fields of the stack are made up of variable to hold its maximum size (the size of the array)the array itselfand variable topwhich stores the index of the item on the top of the stack (note that we need to specify stack size only because the stack is implemented using an array if it had been implemented using linked listfor examplethe size specification would be unnecessary the push(method increments top so it points to the space just above the previous top and stores data item there notice again that top is incremented before the item is inserted the pop(method returns the value at top and then decrements top this effectively removes the item from the stackit' inaccessiblealthough the value remains in the array (until another item is pushed into the cellthe peek(method simply returns the value at topwithout changing the stack the isempty(and isfull(methods return true if the stack is empty or fullrespectively the top variable is at - if the stack is empty and maxsize- if the stack is full figure shows how the stack class methods work error handling there are different philosophies about how to handle stack errors what happens if you try to push an item onto stack that' already full or pop an item from stack that' empty