Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help with this Python problem. Now that we've explored some data structures from the outside, we're going to try to build some of our
Please help with this Python problem.
Now that we've explored some data structures from the outside, we're going to try to build some of our own. We'll focus on various data types for organizing ordered collectionsthat is, different kinds of lists. We will create our data structures as objects, and as we do so, we want to think about keeping the big O running time of their methods as low as possible. 1. A stack is like a list, except that items can only be added or removed from one end (the top of the stack). It is like a stack of booksyou can add a book to the top of the stack, or remove a book from the top of the stack. Stacks are referred to as LIFOLast in, First outdata structures. Implement a stack. This is where we start using object oriented programing to create our own data structures. Your stack can use a python list internally to hold your data. Your stack should implement the following methods: Stack() creates a new stack that is empty. It needs no parameters and returns an empty stack. push(item) adds a new item to the top of the stack. It needs the item and returns nothing. pop(removes the top item from the stack. It needs no parameters and returns the item. The stack is modified. peek() returns the top item from the stack but does not remove it. It needs no parameters. The stack is not modified. isEmpty() tests to see whether the stack is empty. It needs no parameters and returns a boolean value. size() returns the number of items on the stack. It needs no parameters and returns an integer. You will also want to implement a method to print out your stack in order to test your code. In comments, describe the running time of each method of your implementationStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started