Well, you can make a new array that has boolean values that specify if to check a specific index or not. Like this:
#include <stdio.h>
#include <string.h>
const int SIZE = 3;
int a[] = {1, 2, 3};
int b[] = {2, 3, 0};
int compare(int array1[], int array2[])
{
int same = 0;
// boolean values array specifying to check an index or not
int tocheck[SIZE];
// initially we want to check all
memset(tocheck, 1, SIZE);
int i, j;
for (i = 0; i < SIZE; i++)
{
for (j = 0; j < SIZE; j++)
{
// if we need to check, check!
if (tocheck[j])
{
if (array1[i] == array2[j])
{
same++;
// we checked this one, no need to check it anymore
tocheck[j] = 0;
}
}
}
}
return same;
}
int main(void)
{
printf("Same: %d\n", compare(a, b));
return 0;
}
It does run in O(n^2), but it is correct though.