Question: Please use python to answer this question! Thanks! 3. Inheritance (based on 8.38) You MUST use inheritance for this problem. A stackis a sequence container
Please use python to answer this question! Thanks!
3. Inheritance (based on 8.38) You MUST use inheritance for this problem. A stackis a sequence container type that, like a queue, supports very restrictive access methods: all insertions and removals are from one end of the stack, typically referred to as the top of the stack. A stackis often refered to as a last-in first-out (LIFO) container because the last item inserted is the first removed. Implement a Stack class using inheritance. Note that this means you may be able to inherit some of the methods below. Which ones? (Try not writing those and see if it works!) a. Constructor/ init -Can construct either an empty stack, or initialized with a list of items, the first item is at the bottom, the last is at the top b. push-take an item as input and push it on the top of the stack C. pop ( )-remove and return the item at the top of the stack d. sEmpty -returns True if the stack is empty, False otherwise e. return the item at a given location, [O] is at the bottom of the stack f. len) -return length of the stack The object is to make this client code work: >>3 Stack) g.pushl'apple') Stackcl'apple']) >.pushl'pear') 'kiwi') Stack(l'apple, 'pear', 'kiwi']) tor kiwi Stack(l'apple, 'pear']) 2 False >>3.pop.) pear apple True >>> 3 = Stack( [ ' apple' , >>> 3 = Stack( [ ' apple' , 'pear ' , 'pear ' ' ' kiwi' ] ) ' kiwi' ] ) apple
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
