Question: PLZ write it in Python! Let us implement a special bot using a Stack data structure. This bot holds an empty sequence of data named
PLZ write it in Python!
Let us implement a special bot using a Stack data structure. This bot holds an empty sequence of data named data items when initialized. It then reads a list of string operations as input and performs the corresponding manipulation on data items. The i-th item in the input list represents one operation that the bot needs to perform. The types of the operations are the follows:
1. A: add a new integer to data items that is the sum of the previous two integer values in data items
2. T: add a new integer to data items that is the triple of the previous integer value in data items.
3. D: Delete the previous integer value from data items.
4. An integer: Add the integer to data items. Your goal is to implement a Stack and use it to implement the special bot described above.
The bot should have a function that takes a valid list of strings as input and return the sequence of integers that the bot collected in data items. Write your own test case to demo how your algorithm works. For simplicity, you can assume that the input list is always valid. However, we encourage you to think about how to handle invalid cases. Hint: I can give you one test case. Input: operations = [10,3,D, T,A], your bot should output [10, 30, 40]. data items could be a Stack.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
