Question: create a class called MyQueueADT that implements a queue for a series of objects. implement the queue What kind of objects? to store the
create a class called MyQueueADT that implements a queue for a series of objects. implement the queue What kind of objects? to store the objects. For YOUR queue, new items should be added to the end. That's the point of ADTs - you don't need to know what the data is or what it represents. In addition to the methods enqueue, dequeue, is_empty, and peek, you should define the magic method _str_ which non- destructively iterates through all the data from the queue and returns it as a string, with newline separators between items. You can assume the objects will have their own _str_ magic methods. create a class called MyStackADT that implements a stack for a series of objects. implement the stack to store the objects. That's the point of ADTS - you don't need to know what the data is or what it represents. In addition to the methods push, pop, is_empty, and peek, you should define the magic method _str_ which non-destructively iterates through all the data from the stack and returns it as a string, with newline separators between items. You can assume the objects will have their own_str_ magic methods. Expressions can be written in a form called postfix notation (also known as Reverse Polish Notation, or RPN). In such a system, the expression: ab+cd-* = would be rendered as the infix expression ((a + b) (cd)) Infix is the standard way we do our math. Note that RPN has no parentheses; the order operations are presented implies the processing order. In converting, every time an expression is created, it is enclosed in parentheses. We can therefore see, in the above example, that three expressions are created: (a + b), (c - d), and the final expression using the two original expressions as operands. We shall only consider 4 operators: +, -, *, / The sign shall be the signal that the RPN expression is terminated. You would then return the result. Using the MyStackADT you built in a previous problem, convert given expressions from postfix to infix by creating a function called postfix_to_infix which takes a string expression representing an RPN expression, and returns a string expression of the equivalent infix expression. How do you do this? You read the string, element by element. If the element is a space (" "), ignore it. Otherwise, check if the element is "=". If it is, pop the item on the stack and return it. If it's one of the defined operators (that is, if it's in that defined set of operators): 1. Pop the second operand and store it in a variable 2. Pop the first operand and store it in a variable 3. Construct a string with open parenthesis, the first operand, the operator, the second operand, and the close parenthesis. 4. Push that string back onto the stack - it may be an operand for a later expression. Otherwise, it's a symbol. Push it onto the stack. That's all there is to it. Our code will test your postfix_to_infix function.
Step by Step Solution
3.52 Rating (152 Votes )
There are 3 Steps involved in it
To summarize you need to create a class called MyStackADT that implements a stack for a series of ob... View full answer
Get step-by-step solutions from verified subject matter experts
