Write a program that will reverse the content of a Queue using the following standard queue...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a program that will reverse the content of a Queue using the following standard queue operations. enqueue(x): Add an item x to rear of queue. dequeue(): Remove an item from front of queue. empty(): Checks if a queue is empty or not. For reversing the queue one approach could be to store the elements of the queue in a temporary data structure in a manner such that if we re-insert the elements in the queue they would get inserted in reverse order. So now our task is to choose such data-structure which can serve the purpose. According to the approach, the data-structure should have the property of 'LIFO' as the last element to be inserted in the data structure should be the first element of the reversed queue. Using the new data structure to store the elements of the queue temporarily should: Pop the elements from the queue and insert into the new data structure. (first element of the data 121 Panor structure is last element of the queue) Pop the elements of the data structure to insert back into the queue. (The last element of the data structure is the first one to be inserted into the queue) Input Format The program should accept N series of integer values where 1 ≤ N≤ 10 separated by a space and stored in a queue. If the input Winteger exceeds the allowed number of input the program should display an error message. Example Input Enter N Integer values: 1 2 3 4 5 6 7 8 9 10 Output Format The program should display the reverser order of the queue elements in a single line separated by a space. (Note: that only queue standards operations can be used to display the queue elements). Example Output Reverse Queue: 10 987654321 Example Program Execution Enter N Integer values: 10 40 60 20 80 Reverse Queue: 80 20 60 40 10 Write a program that will reverse the content of a Queue using the following standard queue operations. enqueue(x): Add an item x to rear of queue. dequeue(): Remove an item from front of queue. empty(): Checks if a queue is empty or not. For reversing the queue one approach could be to store the elements of the queue in a temporary data structure in a manner such that if we re-insert the elements in the queue they would get inserted in reverse order. So now our task is to choose such data-structure which can serve the purpose. According to the approach, the data-structure should have the property of 'LIFO' as the last element to be inserted in the data structure should be the first element of the reversed queue. Using the new data structure to store the elements of the queue temporarily should: Pop the elements from the queue and insert into the new data structure. (first element of the data 121 Panor structure is last element of the queue) Pop the elements of the data structure to insert back into the queue. (The last element of the data structure is the first one to be inserted into the queue) Input Format The program should accept N series of integer values where 1 ≤ N≤ 10 separated by a space and stored in a queue. If the input Winteger exceeds the allowed number of input the program should display an error message. Example Input Enter N Integer values: 1 2 3 4 5 6 7 8 9 10 Output Format The program should display the reverser order of the queue elements in a single line separated by a space. (Note: that only queue standards operations can be used to display the queue elements). Example Output Reverse Queue: 10 987654321 Example Program Execution Enter N Integer values: 10 40 60 20 80 Reverse Queue: 80 20 60 40 10
Expert Answer:
Answer rating: 100% (QA)
Python class Queue def initself selfitems def enqueueself item selfitemsapp... View the full answer
Related Book For
Data Structures and Algorithm Analysis in Java
ISBN: 978-0132576277
3rd edition
Authors: Mark A. Weiss
Posted Date:
Students also viewed these computer network questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Demand function for a firm is given as P-100e, if the firm's average cost (AC) is AC 5+50, determine the firm's maximum profit. (5marks).
-
On April 12, 2011, BAM Technologies floated a $100 million bond issue. Each $1,000 bond entitled the bondholder to receive $50 every six months (October 12th and April 12th) until April 12, 2041, at...
-
Air enters a 28-cm diameter pipe steadily at 200 kPa and 20°C with a velocity of 5 m/s. Air is heated as it flows, and leaves the pipe at 180 kPa and 40°C. Determine (a) The volume flow rate...
-
As a money manager based in the Netherlands, you are asked to advise a domestic client about investing in foreign bonds to diversify domestic inflation risk. You fear that
-
Does Fairmont have any contactor personnel whose have terminated but are being paid through payroll after termination (e.g., ghost employees)?
-
Home Products Company manufactures a complete line of kitchen glassware. The Beverage Division specializes in 12-ounce drinking glasses. Erin Fisher, the superintendent of the Beverage Division,...
-
Salazar and child, Tahmores, are cash basis taxpayers. Salazar gave Tahmores a corporate bond with a face amount and fair market value of $10,000. On the date of the gift, September 30, 2023, the...
-
KEW Enterprises began operations in January 2015 to manufacture a hand sanitizer that promised to be more effective and gentler on the skin than existing products. Family members, one of whom was...
-
If for a Class T bear the concrete strength at transfer and before losses is 4000 psi, and the 28-day concrete compressive strength is 6000 psi, what is the allowable compressive stress at transfer...
-
What is market segmentation? What role does it play in strategic positioning?
-
An employee who works on the fifth floor of the headquarters of Patterson & Millers, a multinational law firm based in central London, is assigned to a new office on the eighth floor during his third...
-
Robert has entered a competition in which he must drive from his home town of Paris to London, a distance of approximately 450 km. If he arrives in 5 hours (an average speed of 90 km/h), he will...
-
What is strategic coherence?
-
Who are a firms stakeholders? Why are they important?
-
Accountancy Company acquired 75% of the outstanding shares of Finance Company for P900,000. The book value of Finance Company's net assets is P1,000,000. Upon re-measurement of the acquiree's net...
-
If a test has high reliability. O the test measures what the authors of the test claim it measures O people who take the same test twice get approximately the same scores both times O scores on the...
-
Write a program to take N elements and do the following: a. Insert them into a heap one by one. b. Build a heap in linear time. Compare the running time of both algorithms for sorted,...
-
Show how to implement three stacks in one array.
-
Suppose that the edges in an undirected graph G satisfy the triangle inequality: cu,v + cv,w cu,w. Show how to compute a traveling salesman tour of cost at most twice optimal.
-
We can make a static measurement to deduce the spring constant to use in the model. If a \(61 \mathrm{~kg}\) woman stands on a low wall with her full weight on the ball of one foot and the heel free...
-
A \(1.00 \mathrm{~kg}\) block is attached to a horizontal spring with spring INT constant \(2500 \mathrm{~N} / \mathrm{m}\). The block is at rest on a frictionless surface. A \(10.0 \mathrm{~g}\)...
-
If, during a stride, the stretch causes her center of mass to lower by \(10 \mathrm{~mm}\), what is the stored energy? A. \(3.0 \mathrm{~J}\) B. \(6.0 \mathrm{~J}\) C. \(9.0 \mathrm{~J}\) D. \(12...
Study smarter with the SolutionInn App