create a class called MyQueueADT that implements a queue for a series of objects. implement the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
To summarize you need to create a class called MyStackADT that implements a stack for a series of ob... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
Lacy Construction has a noncontributory, defined benefit pension plan. At December 31, 2024, Lacy received the following information: ($ in millions) Projected Benefit Obligation Balance, January 1...
-
Macroware Corporation reported the following information in its financial statements for three successive quarters ($ in millions): Balance Sheets: 6/30/2020 (Q4) Three Months Ended 3/31/2020 (Q3)...
-
BONUS (5 points) You plan to retire at 65 and want an annuity that will pay you $3700 a month for 30 years from an account that pays 3.75% interest. How much needs to be in your account?
-
The figure below represents a schematic of pipe network. A rate of 35 Ls, is pumped to feed two lines (3-4-5-6; and 2-7-8). The length and diameter of each pipe segment are listed in the table....
-
Water at 200 kPa, x = 1.0 is compressed in a piston/cylinder to 1 MPa, 350oC in a reversible process. Find the sign for the work and the sign for the heat transfer.
-
Highlight, Inc., owns all outstanding stock of Kiort Corporation. The two companies report the following balances for the year ending December 31, 2013:...
-
The following stream at \(100^{\circ} \mathrm{F}\) and 300 psia is to be separated into four essentially pure products. Also given is the cost of each unique separator. Determine the best sequence....
-
Dansville Restaurant Supply manufactures commercial stoves and ovens for restaurants and bakeries. The company uses job costing to calculate the costs of its jobs with direct labor cost as its...
-
Calculate and report the classification accuracy for the given confusion matrix. 215 0 2 0 5 2 224 0 135 34 0 2 40 211 0 16 368 1 0 12 397 1 0 2 458 0 0 461 3 0 1 20 183 183 30 237 36 219 o 187 419...
-
Go to the Webinars worksheet. DeShawn wants to determine the number of webinars the company can hold on Tuesdays and Thursdays to make the highest weekly profit without interfering with...
-
Explain and work on activity ratio of Disney world comparing 2013 to 2015
-
Describe some of the ways in which Georg Simmel's study of society differed from that of other major social theorists of his age. Identify and explain at least six (6) key concepts used by Simmel in...
-
Describe a government service or product that either the government charges money for -- or could charge money for -- and then discuss briefly whether you think the government's fee promotes...
-
Why does the quantity of Norwegian krone increase when the demand increases? The Norwegian central bank does not intervene, So how is it possible?
-
What is FDI, why has it grown so dramatically in recent decades, and what trends are evident in its distribution between states? Explain.
-
Some critics of using economics in medical decision-making confuse resource allocation with resource rationing. What is the difference between the two concepts?
-
55 A case control study of adult men and women is performed to determine the relationship of obesity to cancer. The dataindicate an increased risk for cancers of the esophagus and kidney in subjects...
-
a. Determine the domain and range of the following functions.b. Graph each function using a graphing utility. Be sure to experiment with the window and orientation to give the best perspective of the...
-
You have three identical prizes to give away and a pool of ten finalists. The finalists are assigned numbers from 1 to 10. Write a program to randomly select the numbers of three finalists to receive...
-
Write a program that demonstrates the operator % by performing the following tasks: Use Scanner to read a floating-point value x. Compute x % 2.0 and store the result in y. Display x and y clearly...
-
The following code fragment will not compile. Why? if !x > x + y x = 2 * x; else x = x + 3;
-
Over a 5-year period, Eureka Ltd completed the following transactions affecting non-current assets in financial years ending 30 June. The company uses straight-line depreciation on all depreciable...
-
On 2 January 2024, Omega Ltd purchased, by exchanging \($420\) 000 cash and a \($250\) 000, 12%, 18-month finance company loan, assets with the following independently determined appraised values....
-
Pioneer Manufacturing Ltd completed the following transactions during 2023: Required Prepare journal entries to record all the transactions of Pioneer Manufacturing Ltd from 1 July 2023 to 30 June...
Study smarter with the SolutionInn App