#ifndef __ARRAY_UTILS_H__ #define __ARRAY_UTILS_H__ /** * Procedure: * swap * Parameters: * a, an array of integers * i, an integer * j, an integer * Purpose: * Swap the values at positions i and j of a. * Produces: * [Nothing; Called for the side effect.] * Preconditions: * 0 <= i < length(a) * 0 <= j < lenggh(a) * X = a[i] * Y = a[j] * Postconditions: * a[i] = Y * a[j] = X */ void swap (int a[], int i, int j); /** * Procedure: * largest * Parameters: * a, an array of integers * limit, an integer * Purpose: * Finds the largest integer in the first limit values of a. * Produces: * l, an integer * Preconditions: * 0 < limit <= length(a) * Postconditions: * a has not been modified * For all i in the range [0..limit), l >= a[i]. */ int largest (int a[], int limit); /** * Procedure: * index_of * Parameters: * a, an array of integers * limit, an integer * value, an integer * Purpose: * Finds an index of i in a. * Produces: * index, an integer * Preconditions: * 0 <= limit <= length(a) * Postconditions: * a has not been modified * If there exists a j in [0..limit) s.t. a[j] == value, then * index >= 0 and a[index] == value * If no such j exists, then * index == -1 */ int index_of (int a[], int limit, int value); /** * Procedure: * index_of_largest * Parameters: * a, an array of integers * limit, an integer * Purpose: * Finds the index of the largest integer in the first limit values of a. * Produces: * index, an integer * Preconditions: * 0 < limit <= length(a) * Postconditions: * a has not been modified * 0 <= index < limit * For all i in the range [0..limit), a[index] >= a[i]. */ int index_of_largest (int a[], int limit); /** * Procedure: * selection_sort * Parameters: * values, an array of integers * len, an integer * Purpose: * Sorts the first len values of values. * Produces: * [Nothing; Called for the side effects.] * Preconditions: * 0 <= len < length(values) * Postconditions: * values contains a permutation of its original values * values[i] <= values[i+1] for i in [0..len-1) */ void selection_sort (int values[], int len); #endif