Consider the LinkedIntList class given in the book and covered in Chapter 16. Su
ID: 3847374 • Letter: C
Question
Consider the LinkedIntList class given in the book and covered in Chapter 16.
Suppose we create an array of LinkedIntList objects, as in the code below:
Now suppose we begin to add nodes to each LinkedList, as in the code below:
What happens to the array, in memory, when nodes are added to the LinkedIntLists that the array holds? Does the amount of memory used by the array need to be adjusted as the linked lists grow, or does the amount of memory used by the array stay constant? Are the LinkedIntList objects actually added to the array, or are they all deleted when the for loop is finished?
Answer with complete sentences.
LinkedIntList a new LinkedIntList[n] for i 0; ikn; i++) LinkedIntList list new LinkedIntListo; a[i] listExplanation / Answer
The array a[] will have a fixed length of n. As elements are added to any of the linked list in the array , a new node will be added to the corresponding list increasing the size of the linked list.
For example, a[1].add(10); a[1].add(11) will increase increase the size of LinkedIntList at index 1 by 2 nodes.
When the for loop terminates all the elements in the array are initialized with empty LinkedIntList objects.
Hope the answer helps. If any doubts, please post a comment and I shall respond. If satisfied with the answer, please rate it. Thank you very much.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.