#include "is-permutation.h" int is_permutation (int a1[], int a2[], int size) { int i; for (i = 0; i < size; i++) { if (index_of (a1, size, a2[i]) == -1) return 0; if (index_of (a2, size, a1[i]) == -1) return 0; } // for return 1; } // is_permutation /** * 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) { int i; for (i = 0; i < limit; i++) if (a[i] == value) return i; return -1; } // index_of