Question: Develop a python class Stack that will offer all the functionalities of traditional stack data structure with the property that the last item to get
Develop a python class Stack that will offer all the functionalities of traditional stack data structure with the property that the last item to get in will be the first item to get out. This class should have the following functions implemented.
push(value) -> Add element value to the top of stack. Error, if stack is at its maximum size. pop() -> Remove and return the top element from the stack; an error occurs if the stack is empty. top() -> Return a reference to the top element of stack S without removing it; an error occurs if the stack is empty. length() -> Returns the number of items in the internal list. is_empty(): Return True if the stack does not contain any elements, otherwise False. printStack() -> Prints all the items that are currently present in the stack from the first inserted item to the last one. Note: this function does not remove any item from the internal list.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
