Arrays
| English | Chinese | Pinyin |
|---|---|---|
| array | 数组 | shù zǔ |
| index | 索引 | suǒ yǐn |
| element | 元素 | yuán sù |
| bounds | 边界 | biān jiè |
| nested loops | 嵌套循环 | qiàn tào xún huán |
| linear search | 线性查找 | xiàn xìng chá zhǎo |
Storing many values at once
- An array 数组 is an ordered collection of items of the same type, under one name, reached by an index 索引.
- It's the workhorse for storing lists and tables.
- Loops let you process every element 元素.
An array is a data structure holding many values of the ______ type under one name.
Each value is reached by its index.
1-D arrays
DECLARE Names : ARRAY[1:5] OF STRING
Names[3] ← "Cara"
FOR i ← 1 TO 5
OUTPUT Names[i]
NEXT i
- An element is one item; the bounds 边界 are the lowest and highest valid indices.
- A
FORloop visits every element in turn.

A 1-D array (a list) with indices and bounds
An array stores:
An array is an ordered collection of same-type items accessed by index. (A record groups different types.)
2-D arrays
DECLARE Grid : ARRAY[1:3, 1:4] OF INTEGER
Grid[2, 3] ← 99 // row 2, column 3
- The first index is the row, the second the column; use nested loops 嵌套循环 to visit every cell.
- Use 1-D for a single sequence, 2-D for a grid (rows × columns).

A 2-D array is a grid, indexed by [row, column].
Index a 2-D array by [row, column]
A 2-D array is a grid. Grid[row, column] reaches exactly one cell — change the row and column to see which value you land on.
In Grid[2, 3], which cell is accessed?
The first index is the row, the second the column — so row 2, column 3.
An array holds many items of the SAME type reached by index, while a record groups fields of (possibly) DIFFERENT types reached by name.
A 2-D array suits a grid (rows × columns); a record suits one thing described by several named fields.
Common operations
- Linear search 线性查找 checks each element until found:
FOR i ← 1 TO n
IF A[i] = Target THEN OUTPUT "Found at ", i
NEXT i
- For a sum, count, max or min, set a running variable then sweep through (e.g.
Max ← A[1], then compare each element). - A 2D array is a table with row and column indices, between a lower bound and an upper bound; a bubble sort orders an array by swapping adjacent pairs.
A linear search finds a value by:
A linear search examines elements one by one from the start until it finds the target (or reaches the end).
You've got it
- an array holds many items of the same type, reached by an index, within its bounds
- 1-D = a list; 2-D = a table (
Grid[row, column]), visited with nested loops - a linear search checks each element in turn
- running totals/max/min: initialise a variable, then loop through