One solution to the problem of running out of space for an array-based list implementation is to
Question:
One solution to the problem of running out of space for an array-based list implementation is to replace the array with a larger array whenever the original array overflows. A good rule that leads to an implementation that is both space and time efficient is to double the current size of the array when there is an overflow. Reimplement the array-based List class of Figure 4.2 to support this array-doubling rule.
Transcribed Image Text:
/** Array-based list implementation */ class AList implements List { private static final int defaultSize = 10; // Default size // Maximum size of list private int maxSize; private int listSize; private int curr; private E[] listArray; // Number of list items now // Position current element // Array holding list elements /** Constructors */ /** Create a list with the default capacity. */ AList() { this (defaultSize); } /** Create a new list object. @param size Max number of elements list can contain. */ @SuppressWarnings ("unchecked") // Generic array allocation AList (int size) { } public void clear() // Reinitialize the list { listSize = curr = 0; } // Simply reinitialize values maxSize = size; list Size = curr = 0; listArray (E[]) new Object [size]; // Create listArray /** Insert "it" at current position */ public void insert (E it) { assert listSize < maxSize : "List capacity exceeded"; for (int i=listSize; i>curr; i--) // Shift elements up listArray[i] = listArray [i-1]; // to make room listArray [curr] = it; list Size++; // Increment list size } public void append (E it) { // Append "it" assert listSize < maxSize : "List capacity exceeded"; listArray [listSize++] = it; } public void move ToStart() { curr = 0; } // Reset position
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (1 review)
Java Arraybased list implementation class AList implements List private static final int defaultSize ...View the full answer
Answered By
PALASH JHANWAR
I am a Chartered Accountant with AIR 45 in CA - IPCC. I am a Merit Holder ( B.Com ). The following is my educational details.
PLEASE ACCESS MY RESUME FROM THE FOLLOWING LINK: https://drive.google.com/file/d/1hYR1uch-ff6MRC_cDB07K6VqY9kQ3SFL/view?usp=sharing
3.80+
3+ Reviews
10+ 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
-
In 2012, Professor Vasudev Rao, the Dean Administration of T.A. Pai Management Institute (better known as TAPMI) found himself at cross roads. After moving into this picturesque campus in 2010, one...
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
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...
-
Two companies, Energen and Hastings Corporation, began operations with identical balance sheets. A year later, both required additional manufacturing capacity at a cost of $50,000. Energen obtained a...
-
A large storage tank contains liquefied natural gas (LNG), which may be assumed to be pure methane. The tank contains saturated liquid at ambient pressure, 100 kPa; it is to be pumped to 500 kPa and...
-
For the network in Fig. 2.89 , find the current, voltage, and power associated with the 20-kΩ resistor. 5 mA 10 k2 0.01V. V. 5 k2 20 k2
-
Refer to the statements for Google in Appendix A. For the year ended December 31, 2015, what was its debt-to-equity ratio? What does this ratio tell us? Data From Statement Google In Appendix A...
-
Using the planned orders generated in Problem 17, complete inventory records for components AB501, AB511, and AB521. Use the lot size rule, lead time, and usage information given in Problem 12.
-
Student Name: Anthony Jedruczek (Please PRINT your name) Assume that Q-Caf has the following transactions related to the sale of coffee beans during the month of October, 2023. Oct 1 Oct 5 Oct 15 Oct...
-
Use singly linked lists to implement integers of unlimited size. Each node of the list should store one digit of the integer. You should implement addition, subtraction, multiplication, and...
-
A deque (pronounced deck) is like a queue, except that items may be added and removed from both the front and the rear. Write either an array-based or linked implementation for the deque.
-
By drawing appropriate diagrams, illustrate the fact that BF 3 possesses a 3-fold axis, three 2-fold axes, and four planes of symmetry. Give appropriate labels to these symmetry elements.
-
(c) Consider a competitive producer with a production function of l 0.4 k 0.1 , labor price of w and capital price of 1(not v, the number one), and an output price of p. Suppose capital in the...
-
The What Works in Schools textbook, Marzano reports that there are 11 factors that affect student achievement. Of the 11 factors, which of them are completely out of the teacher's control? Since they...
-
As a seasoned lending officer with Royal Bank, you are very familiar with the federal regulations related to the stress test requirement when dealing with mortgage requests from your customers. You...
-
Summarize the threats and challenges you have identified within the current strategic plan. Determine how to execute the strategic initiatives in order to address the threats and challenges. Explain...
-
Herzberg referred to demotivators in the workplace as hygiene factors. Hygiene factors are conditions that, if present, do not motivate, but if absent, can be significant demotivators. Relying on...
-
You and two friends drive your car to Texas for spring break. A third friend asks if you can drop her off in Oklahoma. How would you allocate the cost of the trip among the four of you?
-
Under what conditions is the following SQL statement valid?
-
What are the two components of a signal when the signal is represented on a constellation diagram? Which component is shown on the horizontal axis? Which is shown on the vertical axis?
-
How many bits per baud can we send in each of the following cases if the signal constellation has one of the following number of points? a. 2 b. 4 c. 16 d. 1024
-
Define constellation diagram and explain its role in analog transmission.
-
Ruby is a manager who is considered a consistent decision maker. She prefers to make quick decisions that fulfill the minimum criteria for a decision rather than spending too much time weighing out...
-
Team Building Team Norms Team Diversity Team Building. Research, critique and discuss this article in the light of our topic.
-
discuss the role of relational algebra and relational calculus in defining and querying data relationships within a relational database management system (RDBMS), emphasizing their impact on query...
Study smarter with the SolutionInn App