CJCoding With Joseph
15free / daySign inCreate account

A DynamicArray keeps its values in an ordinary int array called data, but only the first size slots are in use. The array is usually longer than that, and the spare slots still hold a leftover 0. So a safe read checks the index against size, never against the length of the array.

Requirements: 1. get(int index) returns the value stored at that position. 2. It returns -1 when index is negative or is not less than size, even when that slot exists in the array. 3. Do not change any other method.

Do NOT write a main method.

Expected output

10
30
20
-1
-1

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

Hints3 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.