#include "is-permutation.h" int is_permutation (int a1[], int a2[], int size) { int i; for (i = 0; i < size; i++) { // This is made a little bit more step-by-step than normal for // clarity. Basically, we make sure that every element of a2 // appears the same number of times in a2 and a1. int val = a2[i]; int c1 = count (a1, size, val); int c2 = count (a2, size, val); if (c1 != c2) return 0; } // for return 1; } // is_permutation int count (int a[], int limit, int value) { int i; int count = 0; for (i = 0; i < limit; i++) if (a[i] == value) ++count; return count; } // count