程式設計基礎/並行陣列
外觀
< 程式設計基礎
一組並行陣列是一種隱式資料結構形式,它使用多個數組來表示單個記錄陣列。它為記錄的每個欄位保留一個獨立的、同構的資料陣列,每個陣列都有相同數量的元素。然後,每個陣列中位於同一索引處的物件隱式地構成單個記錄的欄位。[1]
資料結構是資料的組織和儲存格式,它可以有效地訪問和修改資料。更確切地說,資料結構是資料值的集合、它們之間的關係以及可以應用於資料的函式或操作。資料結構選項包括陣列、連結串列、記錄和類。[2]
並行陣列使用兩個或多個數組來表示資料的集合,其中每個對應的陣列索引是給定記錄的匹配欄位。例如,如果有兩個陣列,一個用於姓名,一個用於年齡,則陣列“姓名”和“年齡”在索引[2]處的陣列元素將描述第三個人的姓名和年齡。這是因為陣列從 0 開始計數。
Function Main
Declare String Array names[5]
Declare Integer Array ages[5]
Assign names = ["Lisa", "Michael", "Ashley", "Jacob", "Emily"]
Assign ages = [49, 48, 26, 19, 16]
DisplayArrays(names, ages)
End
Function DisplayArrays (String Array names, Integer Array ages)
Declare Integer index
For index = 0 to Size(name) - 1
Output names[index] & " is " & ages[index] & " years old"
End
End
Lisa is 49 years old Michael is 48 years old Ashley is 26 years old Jacob is 19 years old Emily is 16 years old
- 並行陣列
- 一種使用多個數組來表示單個記錄陣列的隱式資料結構。