Figure 7.3 passes integer max_items to the queue abstraction as a generic parameter. Write an alternative version
Question:
Figure 7.3 passes integer max_items to the queue abstraction as a generic parameter. Write an alternative version of the code that makes max_items a parameter to the queue constructor instead. What is the advantage of the generic parameter version?
Figure 7.3:
Transcribed Image Text:
template
template class queue { item items [max_items]; int next_free, next_full, num_items; public: queue () : next_free(0), next_full(0), num_items (0) { } bool enqueue (const item& it) { if (num_items == max_items) return false; ++num_items; items [next_free] it; next_free (next_free + 1) % max_items; %3D return true; bool dequeue (item* it) { if (num_items 0) return false; *it = items [next_full]; --num_items; next_full = (next_full + 1) % max_items; %3D return true; }; queue ready_list; queue int_queue;
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 60% (10 reviews)
NB Like Figure 73 this code does not check for overflow or underflow The advanta...View the full answer
Answered By
Namita Jambhule
I am currently pursuing Masters degree in structural engineering from VNIT, Nagpur. I love to clear the basic concepts of the students and help them with their academics in my free time. I have been taking the labs and assignments of bachelor students. I have also experience of teaching strength of materials to the students. I have hands on experience of softwares such as Autocad, Abaqus, SAP2000.
0.00
0 Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
Modify the code of Figure 7.3 or your solution to Exercise 7.12 to throw an exception if an attempt is made to enqueue an item in a full queue, or to dequeue an item from an empty queue. Data From...
-
An alternative version of Gresham's Law is that "Bad money drives out good money." Why is it true that, in choosing between different currencies to transact in, good money drives out bad money?
-
The code that you add to the Craps main method needs to do the following steps in the following order (where indicated by the comments in the code itself): 1. Declare an integer array named counts...
-
Since its 100% acquisition of Dancer Corporation stock on December 31, 2012, Jones Corporation has maintained its investment under the equity method. However, due to Dancer's earning potential, the...
-
A well in a confined aquifer is pumped at a rate of 833 liters/min (1199.5 m3/day) for a period of over 8 hr. Time-drawdown data for an observation well located 250 m away are given below. The...
-
On November 1, 2020, Cheng Company (a U.S.-based company) forecasts the purchase of goods from a foreign supplier for 100,000 yuan. Cheng expects to receive the goods on April 30, 2021, and make...
-
Bradshaw Bakeries Ltd is evaluating investment alternatives for three machines and has compiled the following relevant information. The company requires a 10% minimum return on new investments....
-
Recent graduate and world traveler Alastair Bor is planning a European trip. He is influenced by his curiosity about urban culture in the EU and by his study of international relations while he was...
-
At the beginning of April, a company has a balance of $12,800 in the Retained Earnings account. During the month of April, the company had the following external transactions. Required: Using the...
-
Write a test program that stores 5 million integers in a linked list and test the time to traverse the list using an iterator vs. using the get(index) method.
-
In your favorite language with generics, write code for simple versions of the following abstractions: (a) A stack, implemented as a linked list (b) A priority queue, implemented as a skip list or a...
-
Rewrite the generic sorting routine of Examples 7.507.52 (with constraints) using OCaml or SML functors.
-
What will the following code display? numbers = [1, 2, 3, 4, 5] numbers [2] = 99 print (numbers)
-
Suppose the pandas table has one row with the name Mei Xiang and the location DC. What does the following code output? A. Mei Xiang B. No match C. The code does not compile due to line s1. D. The...
-
Suppose we have an empty bunny table with two columns: name and color. What is the state of the table after running this code? A. Only one row has the color Brown set. B. It has two rows, and the...
-
Consider the three methods execute(), executeQuery(), and executeUpdate(). Fill in the blanks: _______ of these methods is/are allowed to run a DELETE SQL statement while ________ of these methods...
-
Which method in DriverManager is overloaded to allow passing a username and password? A. conn() B. connect() C. forName() D. getStatement() E. open() F. None of the above
-
What is the most likely outcome of this code if the people table is empty? A. It prints false false. B. It prints true false. C. It does not terminate. D. It throws a SQLException. E. None of the...
-
Heineken N.V. reports the following information for its loans and borrowings as of December 31, 2014, including proceeds and repayments for the year ended December 31, 2014 (euros in millions). Loans...
-
1. Using the information from Problem 16-4B, prepare a statement of cash flows for Lim Garden Supplies Inc. using the direct method of presenting cash flows from operating activities. 2. How does Lim...
-
Assume 185 and 122 are unsigned 8-bit decimal integers. Calculate 185 122. Is there overflow, underflow, or neither?
-
Assume 185 and 122 are signed 8-bit decimal integers stored in sign-magnitude format. Calculate 185 + 122. Is there overflow, underflow, or neither?
-
Assume 185 and 122 are signed 8-bit decimal integers stored in sign-magnitude format. Calculate 185 - 122. Is there overflow, underflow, or neither?
-
Discuss the dynamic organization of the cytoskeleton and its pivotal role in cellular motility, intracellular transport, and structural integrity .
-
Would you support the idea of a government issued Digital currency? Why ? and why not?
-
To protect her savings against further inflation and to help her prepare for a healthy financial future, Hanna Lind deposits $9,100 in an investment account earning 6% interest compounded quarterly....
Study smarter with the SolutionInn App