CJCoding With Joseph
15free / daySign inCreate account

Searching a dynamic array is a plain scan from the front, with one trap: the array data is usually longer than the list. Only the first size slots are in use, and the spare slots hold a leftover 0 that is not part of the list.

Requirements: 1. indexOf(int value) returns the index of the first slot in use that holds value. 2. It returns -1 when no slot in use holds it. A 0 that sits in a spare slot must not be found.

Do NOT write a main method.

Expected output

1
2
0
-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.