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: 55% (9 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...
-
Employee salaries are examples of: a. Interval data. b. Ratio data. c. Ordinal data. d. Unstructured data.
-
What is a contra-asset? Give an example of one.
-
Ralphs Bow Works (RBW) is planning to add a new line of bow ties that will require the acquisition of a new knitting and tying machine. The machine will cost $1,000,000. It is classified as a 7-year...
-
Bonita Industries sells two types of computer hard drives. The sales mix is 30% (Q-Drive) and 70% (Q-Drive Plus) based upon quantity of units sold. Q-Drive has a unit variable cost of $100 and a...
-
How are leases classified for tax purposes? MINI CASE Lewis Securities Inc. has decided to acquire a new market data and quotation system for its Richmond home office. The system receives current...
-
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.
-
(a) Deduce the structure of the disaccharide trehalose from the following information: Complete hydrolysis yields only D-glucose; it is hydrolyzed by -glucosidase but not -glucosidase; and it does...
-
Discuss ways that you can improve an internet-based content system management systems performance in terms of latency, security, data availability, and migration. Your response should list at least...
-
2. In January 2016, the Free Cancer Foundation accepted an endowment of $500,000, the income from which is restricted to promoting research related to recovery from cancer. All gains, whether...
-
Calculate the percentage price change for 4 bonds with different annual coupon rates (5% and 10%) and different maturities (3 years and 10 years), starting with a common 7.5% YTM (with annual...
-
A 55 year old employee, earning $50,000 per year is enrolled in only one 401k plan (a traditional 401k). What is the maximum tax deductible contribution she can make to her 401k in 2022?
-
Discuss the strategic issues, including the revenue flow to the state and the likely player, involved in choosing between those games. Would the strategy differ according to whether the state lottery...
-
Pacific Hotels Inc., a large hotel chain, had Retained Earnings of $250.0 million at the beginning of 2014. The company showed these figures at December 31, 2014:...
-
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?
-
Use factoring by grouping to solve the following equation. 3-522-16r+80=0 Enter the solutions, separated by commas if necessary. Do not use a plus-minus () sign when entering separate answers....
-
What are some intervention policies that make provisions for destitute college or university students in Ethiopia? Please provide Examples
-
Develop a simple application of two- variable linear programming problem to find an optimal product mix in a 'realistic' context. Specify the resources to be considered requirements, and the market...
Study smarter with the SolutionInn App