when the outer while loop terminates after the negative value is extractedthe contents of the stack will be as illustrated in figure notice the last value entered is at the top and the first is at the base if we pop the values from the stackthey will be removed in the reverse order from which they were pushed onto the stackproducing reverse ordering figure resulting stack after executing the sample application implementing the stack the stack adt can be implemented in several ways the two most common approaches in python include the use of python list and linked list the choice depends on the type of application involved using python list the python list-based implementation of the stack adt is the easiest to implement the first decision we have to make when using the list for the stack adt is which end of the list to use as the top and which as the base for the most efficient orderingwe let the end of the list represent the top of the stack and the front represent the base as the stack growsitems are appended to the end of the list and when items are poppedthey are removed from the same end listing on the next page provides the complete implementation of the stack adt using python list the peek(and pop(operations can only be used with non-empty stack since you cannot remove or peek at something that is not there to enforce this requirementwe first assert the stack is not empty before performing the given operation the peek(method simply returns reference to the last item in the list to implement the pop(methodwe call the pop(method of the list structurewhich actually performs the same operation that we are trying to implement that isit saves copy of the last item in the listremoves the item from the listand then returns the saved copy the push(method simply appends new items to the end of the list since that represents the top of our stack