< previous page page_626 next page >

Page 626
// Postcondition:
//     IF inputChar is in charList
//         found == TRUE && charList[index] == inputChar
//     ELSE
//         found == FALSE && index is undefined

{
    index = 0;
    while (index < length && inputChar != charList[index])

            // Invariant (prior to test):
            //     inputChar is not in charList[0..index-1]
            //  && 0 <= index <= length

        index++;

    // Assert:
    //     (index == length  &&  inputChar is not
    //                           in charList[0..length-1])
    //  OR (index < length  &&  inputChar == charList[index])

    found = (index < length);
}

//******************************************************************

void Print (
        /* in */ const int  freqList[],     // List of char counts
        /* in */ const char charList[],     // List of chars counted
        /* in */ int        length     )    // Length of lists

// Prints character list with associated frequencies

// Precondition:
//     length <= MAX_LENGTH
//  && freqList[0..length-1] are assigned
//  && charList[0..length-1] are assigned
// Postcondition:
//     charList[0..length-1] and freqList[0..length-1] have been
//     printed

{
int index;  // Loop control and index variable

 
< previous page page_626 next page >