There are many ways to store data. So far, we have covered linear recursive structures, lists, and binary recursive structures, trees. Let's consider another way of storing data, as a contiguous, numbered (indexed) set of data storage elements:
anArray =
itemA |
itemB |
itemC |
itemD |
itemE |
itemF |
itemG |
itemH |
itemI |
itemJ |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
This "array" of elements allows us to access any individual element using a numbered index value.
Definition: array
At its most basic form, a random access data structure where any element can be accessed by specifying a single index value corresponding to that element.
Example
anArray[4] gives us itemE. Likewise, the statement anArray[7] = 42 should replace itemH with42.
- 2021 reads