CJCoding With Joseph
15free / daySign inCreate account

A Java array can never change its length, so a dynamic array grows by moving house: it makes a longer array, copies its values across, and uses the new array from then on. add already calls grow() whenever every slot is in use. size is the number of slots in use, and at the moment grow() runs it equals the length of data.

Requirements: 1. grow() creates a new int array twice as long as data. 2. It copies the values in use into the same positions of the new array. 3. It makes data refer to the new array. size does not change.

Do NOT write a main method.

Expected output

[10, 20, 30, 40] capacity 4
[10, 20, 30, 40, 50] capacity 8
5

= newline. The output ends with a newline, so print one after the last line.

Hints4 available
Topics
Data Structures & AlgorithmsDynamic Arrays
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.