Answer: Invariants

Question: Write invariants at the indicated space in the following functions.

bool
sequentialSearch(ListNode *head, int key) {
    for(ListNode *n = head; n; n = n->next) {
        // INVARIANT: ??
        if(n->data == key) return true;
    }
    return false;
}

Answer: The key is not in any of the nodes in the list prior to n.


Answer / Program analysis / Review questions / 15-211 A, B