#include <stdio.h>
#include <stdlib.h>

#define SIZE 200

//200 = 10 ms (0 results) WARM
//2000000 = 1s  (1837 results)
//20000000 = 11s  (184835 results)

int comparator(const void * ap, const void * bp){
	int a = *(int*)ap;
	int b = *(int*)bp;
	return (a-b);
}


int main() {
    srand(0xdeadbeef);

    unsigned int *array1 = (unsigned int *)malloc(SIZE * sizeof(unsigned int));
    unsigned int *array2 = (unsigned int *)malloc(SIZE * sizeof(unsigned int));
    unsigned int *result = (unsigned int *)malloc(20 * sizeof(unsigned int));

    for(int i=0; i<SIZE; i++) {
        array1[i] = rand();
        array2[i] = rand();
    }

		int i=0;
		int j=0;
		int old = -1;
		int k =0;

		qsort(array1,SIZE,sizeof(int*),comparator);
		qsort(array2,SIZE,sizeof(int*),comparator);

		while (i<SIZE && j<SIZE){
    	if (array1[i] == array2[j]){
				if (old!=array1[i]){
					old = array1[i];
					result[k++] = old;
				}
				i++;
				j++;
			}
			else if (array1[i] < array2[j])
				i++;
			else
				j++;
		}


    printf("Result size: %d\n",k);

    return 0;
}
