For list operations: a. Write expressions that use list indexing and list procedures. b. Evaluate expressions that use list indexing and list procedures.
AAP-2.N.1 The exam reference sheet provides basic operations on lists, including:
-
accessing an element by index
Text:
aList[i]Block:
aList [i]accesses the element of
aListat indexi. The first element ofaListis at index1and is accessed using the notationaList[1]. -
assigning a value of an element of a list to a variable
Text:
x ← aList [i]Block:
x ← aList [i]assigns the value of
aList[i]to the variablex. -
assigning a value to an element of a list
Text:
aList[i] ← xBlock:
aList [i] ← xassigns the value of
xtoaList[i].Text:
aList[i] ← aList[j]Block:
aList [i] ← aList [j]assigns the value of
aList[j]toaList[i]. -
inserting elements at a given index
Text:
INSERT(aList, i, value)Block:
INSERT aList, i, valueshifts to the right any values in
aListat indices greater than or equal toi. The length of the list is increased by 1, andvalueis placed at indexiinaList. -
adding elements to the end of the list
Text:
APPEND(aList, value)Block:
APPEND aList, valueincreases the length of
aListby 1, andvalueis placed at the end ofaList. -
removing elements
Text:
REMOVE(aList, i)Block:
REMOVE aList, iremoves the item at index
iinaListand shifts to the left any values at indices greater thani. The length ofaListis decreased by 1. -
determining the length of a list
Text:
LENGTH(aList)Block:
LENGTH aListevaluates to the number of elements currently in
aList.
AAP-2.N.2 List procedures are implemented in accordance with the syntax rules of the programming language.