您在這裡

Arrays and Array Processing

6 六月, 2016 - 14:40
Available under Creative Commons-ShareAlike 4.0 International License. Download for free at http://cnx.org/contents/402b20ad-c01f-45f1-9743-05eadb1f710e@37.6

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.

Note: Notice however, that the above definition is not a recursive definition. This will cause problems.