Using a heap, implement the priority queue ADT from Section 7.4. You can store the heap in
Question:
Using a heap, implement the priority queue ADT from Section 7.4. You can store the heap in arrays, similar to the solution to Self-Test Exercise 1. To have FIFO behavior for elements with equal priority, you should have a third array called entered. The value of entered[i] tells when the data in node number i entered the priority queue. For example, the first element added has an entered value of 1, the second element has an entered value of 2, and so on. When you are comparing two elements with equal priority, use the entered value to “break the tie” (so that if two elements have the same priority number, then the one with the earlier entered value will come out of the priority queue first).
Make sure you keep track of how many elements are in the heap so that if the size of the heap reaches the size of the arrays, you can increase the size of the arrays.
Step by Step Answer:
The implementation of the priority queue ADT using a heap could involve the following steps 1 Initia...View the full answer
Students also viewed these Computer science questions
-
Using the heap implementation of a priority queue from Project 1, implement a program that keeps track of the users list of prioritized chores. Data from Project 1 Using a heap, implement the...
-
A Chunklist is like a regular linked list, except each node contains a little fixed size array of elements instead of just a single element. Each node also contains its own "size" int to know how...
-
write a job description for Bill Ryan's job. What other information would you need to write a better job description? Remember, this is a job description, not a help wanted ad. Please do your own...
-
Data Corporation has four employees and provides group term life insurance coverage for all four employees. Coverage is nondiscriminatory and is as follows: a. How much may Data Corporation deduct...
-
In Data Set 4, use average annual temperature for the horizontal scale and use precipitation for the vertical scale. Based on the result, does there appear to be a relationship between average annual...
-
List at least four properties that characterize a communication channel.
-
A off-axis tensile test (Figure 2.14) of a unidirectional AS/3501 carbon/epoxy specimen is conducted with \(\theta=45^{\circ}\) and the applied stress is found to be \(\sigma_{x}=15.44...
-
The net income for Lodi Co. for 2014 was $250,000. For 2014, depreciation on plant assets was $70,000, and the company incurred a gain on disposal of plant assets of $12,000. Compute net cash...
-
The Doppler shift has numerous real-world applications, in science, in engineering, and in many practical problems. Look up "Doppler" and find 9 different practical applications of Doppler shift used...
-
By what percentage does a dilute aqueous solution expand when heated from 15 to 25C? If a 0.500 0 M solution is prepared at 15C, what would its molarity be at 25C?
-
Expand the class from Project 10 or 11 so that there is an extra method that produces a Java Iterator for the bag. Data from Project 10 Write a class for a bag of strings, where the strings are...
-
Use a B-tree to implement the Set class from Figure 10.4. Be sure to write and test small pieces. FIGURE 10.4 The Set of Integers Class IntBalancedSet * public class IntBalancedSet from the package...
-
a) What is so special about a PMSI? b) How does one obtain a PMSI? c) Are the goods in this case inventory or non-inventory? d) What is the difference? e) To obtain priority for a non-inventory PMSI,...
-
How much space does the compiler set aside for students? typedef char String[10]; struct Student Record { String firstName; String lastName; int id; float gpa; int currentHours; int totalHours; };...
-
The OOP phrase message passing is equivalent to what C++ construct?
-
Measurements were made of arsenic concentrations in fish found in Northern Canada. In a sample of 8 whitefish caught in Yellowknife Bay, the mean arsenic concentration in the liver was \(0.32...
-
A Sorted List ADT is to be extended by the addition of function SplitLists, which has the following specifications: SplitLists(SortedType list, ItemType item, SortedType& list1, SortedType& list2) 1....
-
The queue is implemented as a class containing an array of items, a data member indicating the index of the last item put on the queue (rear), a data member indicating the index of the location...
-
Linda, age 37, who files as a single taxpayer, had AGI of $280,000 for 2016. She incurred the following expenses and losses during the year: Medical expenses (before the 10%-of-AGI...
-
Wimot Trucking Corporation uses the units-of-production depreciation method because units-of-production best measures wear and tear on the trucks. Consider these facts about one Mack truck in the...
-
Write down the bit pattern assuming that we are using base 15 numbers in the fraction instead of base 2. (Base 16 numbers use the symbols 09 and AF. Base 15 numbers would use 09 and AE.) Assume there...
-
Write down the bit pattern assuming that we are using base 30 numbers in the fraction instead of base 2. (Base 16 numbers use the symbols 09 and AF. Base 30 numbers would use 09 and AT.) Assume there...
-
Th e following C code implements a four-tap FIR filter on input array sig_in. Assume that all arrays are 16-bit fixed point values. Assume you are to write an optimized implementation this code in...
-
Find f'(x) and find the equation of the line tangent to the graph of f at x = 1. f(x)=(1+4x)(5-4x) f'(x)=
-
Find f'(x) and find the equation of the line tangent to the graph of f at x = 3. f(x)= 5x 2* f'(x)=
-
A bacteria culture starts with 340 bacteria and grows at a rate proportional to its size. After 2 hours there will be 680 bacteria. (a) Express the population P after t hours as a function of t. Be...
Study smarter with the SolutionInn App