0% found this document useful (0 votes)
17 views2 pages

Missing Number

The function takes in two arrays and counts the numbers in the second array that are not present in the first array. It marks the numbers of the first array as visited if present in the second array. It then counts the numbers in the second array not marked visited and allocates an array of that size to return the missing numbers.

Uploaded by

jaxosow419
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Missing Number

The function takes in two arrays and counts the numbers in the second array that are not present in the first array. It marks the numbers of the first array as visited if present in the second array. It then counts the numbers in the second array not marked visited and allocates an array of that size to return the missing numbers.

Uploaded by

jaxosow419
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

int comparator (const void * p1, const void * p2)

{
return (*(int*)p1 - *(int*)p2);
}

int* missingNumbers(int arr_count, int* arr, int brr_count, int* brr, int*
result_count) {

int visited = -1;


int count = 0;

for(int i = 0; i<arr_count; i++)


{
for(int j = 0; j<brr_count; j++)
{
// if(arr[i] == visited)
// {
// break;
// }
if(arr[i] == brr[j])
{
arr[i] = visited;
brr[j] = visited;

}
// printf("%d",arr[j]);

}
}
// for(int k = 0; k<brr_count; k++)
// {
// printf("%d ", brr[k]);
// // if(arr[k] != visited)
// // {
// // a[k] = arr[k] ;
// // }
// }
// for(int k = 0; k<arr_count; k++)
// {
// printf("\n%d ", arr[k]);
// // if(arr[k] != visited)
// // {
// // a[k] = arr[k] ;
// // }
// }
for(int i = 0; i<brr_count; i++)
{
if(brr[i] != visited)
{
count += 1;
}
}
*result_count = count;
int *a = malloc(count * sizeof(int));
for(int i = 0; i < count; i++)
{
for(int j = 0; j<brr_count; j++)
{
if(brr[j] != visited)
{
a[i] = brr[j];
brr[j] = visited;
break;
}
}
}
qsort(a, count, sizeof(int), comparator);

return a;
}

You might also like