Modify the array-based queue definition of Figure 4.25 to use a separate Boolean member to keep track
Question:
Modify the array-based queue definition of Figure 4.25 to use a separate Boolean member to keep track of whether the queue is empty, rather than require that one array position remain empty.
Transcribed Image Text:
// Array-based queue implementation class AQueue implements Queue { private static final int defaultSize = 10; private int maxSize; // Maximum size of queue private int front; // Index of front element private int rear; // Index of rear element private E[] listArray; // Constructors AQueue () { this (defaultSize); } @SuppressWarnings ("unchecked") // For generic array AQueue (int size) { } public void clear() { rear = 0; front = 1; } } maxSize = size+1; rear= 0; front = 1; listArray (E[]) new Object [maxSize]; } = public void enqueue (E it) { // Put "it" in queue assert ((rear+2) & maxSize) != front: "Queue is full"; rear = (rear+1) % maxSize; // Circular increment listArray [rear] = it; } // Array holding queue elements front return it; public E de queue () { assert length () != 0: "Queue is empty"; E it = listArray [front]; public E frontValue () { assert length() != 0 return listArray [front]; // Create listArray // Reinitialize public int length() { return ((rear+maxSize) (front+1) maxSize; // Circular increment // Take element out of queue // Get front value "Queue is empty"; // Return length front + 1) maxSize; } Figure 4.25 An array-based queue implementation.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (QA)
java Arraybased queue implementation class AQueue implements Queue private static final int defaultS...View the full answer
Answered By
Felix Onchweri
I have enough knowledge to handle different assignments and projects in the computing world. Besides, I can handle essays in different fields such as business and history. I can also handle both short and long research issues as per the requirements of the client. I believe in early delivery of orders so that the client has enough time to go through the work before submitting it. Am indeed the best option that any client that can think about.
4.50+
5+ Reviews
19+ Question Solved
Related Book For
Practical Introduction To Data Structures And Algorithm Analysis Java Edition
ISBN: 9780136609117
1st Edition
Authors: Clifford A. Shaffer
Question Posted:
Students also viewed these Computer science questions
-
List three specific parts of the Case Guide, Objectives and Strategy Section (See below) that you had the most difficulty understanding. Describe your current understanding of these parts. Provide...
-
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...
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
Write the Comparison for Legal Factors of China and South Africa
-
An old abandoned salt mine, 100000 m3 in volume, contains air at 290 K, 100 kPa. The mine is used for energy storage so the local power plant pumps it up to 2.1 MPa using outside air at 290 K, 100...
-
In the circuit of Fig. 2.75 , calculate V 1 and V 2 . V2 5 V V,
-
Assume the same information as in question 4. Also assume that beginning work in process had \($6,000\) in conversion cost and that \($84,000\) in conversion is added during this period. What is the...
-
The information listed below refers to the employees of Brennan Company for the year ended December 31, 2013. The wages are separated into the quarters in which they were paid to the individual...
-
Fine Equipment uses a perpetual inventory system and is located in Vancouver, British Columbia, where the PST rate is 7 % . Fine Equipment uses the earnings approach for revenue recognition. The...
-
A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables,...
-
Modify the code of Figure 4.18 to implement two stacks sharing the same array, as shown in Figure 4.20 . Figure 4.18 Figure 4.20 /** Array-based stack implementation */ class AStack implements Stack...
-
There are two production plants for producing widgets out of labor and capital. Plant 1's weekly production function is Plant 2's weekly production function is There is a total of 100 workers...
-
1) What are 2 reasons why stakeholder management is important to project success? 2) What are some possible consequences of stakeholder mismanagement? 3) What if stakeholders have different, or even...
-
How much money does Jessica have in her Education Savings plan if, starting today, she can withdraw $350 per month for four years and her plan earns 7.2% compounded monthly?
-
A 2012 Gallup survey of a random sample of 1014 American adults indicates that American families spend, on average, $151 per week on food. The report further states that, with 95% confidence, this...
-
how to calculate income before tax and interest on PROFORMA sheet
-
What the Marketlands are and what the city plans to do there, using a reference from the cite you got the information from.
-
Is cost-of-goods sold an expense?
-
Why can wastewater treatment requirements in Hawaii be less stringent than those in most locations on the U.S. mainland?
-
Repeat Problem P4-3 for the MLT-3 scheme, but use the following data streams. a. 00000000 b. 11111111 c. 01010101 d. 00011000 Problem 4-3 Draw the graph of the NRZ-L scheme using each of the...
-
Repeat Problem P4-3 for the 2B1Q scheme, but use the following data streams. a. 0000000000000000 b. 1111111111111111 c. 0101010101010101 d. 0011001100110011 Problem 4-3 Draw the graph of the NRZ-L...
-
Define the characteristics of a self-synchronizing signal.
-
The Person-Centered Implementation Plan should include: The individual The individual making decisions with others Steps taken for the individual to have the right to decide Approaches to assist in...
-
Assume instead that the costs of production changed for this monopoly so that the marginal cost (MC) and average total cost (ATC) for every unit was $6. $16 Price $14 $12 $10 $8 56 $6 $4 $2 MCATC D...
-
(a) Define direct foreign investment and multinational corporation (b) What are the benefits that economic theory would claim for direct foreign investment? (c) What are the chief concerns of host...
Study smarter with the SolutionInn App