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 aList at index i. The first element of aList is at index 1 and is accessed using the notation aList[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 variable x.

  • assigning a value to an element of a list

    Text:

    aList[i] ← x
    

    Block:

    aList [i] ← x
    

    assigns the value of x to aList[i].

    Text:

    aList[i] ← aList[j]
    

    Block:

    aList [i] ← aList [j]
    

    assigns the value of aList[j] to aList[i].

  • inserting elements at a given index

    Text:

    INSERT(aList, i, value)
    

    Block:

    INSERT aList, i, value
    

    shifts to the right any values in aList at indices greater than or equal to i. The length of the list is increased by 1, and value is placed at index i in aList.

  • adding elements to the end of the list

    Text:

    APPEND(aList, value)
    

    Block:

    APPEND aList, value
    

    increases the length of aList by 1, and value is placed at the end of aList.

  • removing elements

    Text:

    REMOVE(aList, i)
    

    Block:

    REMOVE aList, i
    

    removes the item at index i in aList and shifts to the left any values at indices greater than i. The length of aList is decreased by 1.

  • determining the length of a list

    Text:

    LENGTH(aList)
    

    Block:

    LENGTH aList
    

    evaluates 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.