forked from thisisshub/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinus-set-operations.c
64 lines (55 loc) · 879 Bytes
/
Minus-set-operations.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <stdlib.h>
struct Array
{
int A[10];
int size;
int length;
};
void Display(struct Array arr)
{
int i;
printf("\nElements are\n");
for(i=0;i<arr.length;i++)
{
printf("%d ",arr.A[i]);
}
}
struct Array* Difference(struct Array *arr1,struct Array*arr2)
{
int i,j,k;
i=j=k=0;
struct Array *arr3=(struct Array *)malloc(sizeof(struct Array));
while(i<arr1->length && j<arr2->length)
{
if(arr1->A[i]<arr2->A[j])
{
arr3->A[k++]=arr1->A[i++];
}
else if(arr2->A[j]<arr1->A[i])
{
j++;
}
else
{
i++;
j++;
}
}
for(;i<arr1->length;i++)
{
arr3->A[k++]=arr1->A[i];
}
arr3->length=k;
arr3->size=10;
return arr3;
}
int main()
{
struct Array arr1={{2,9,21,28,35},10,5};
struct Array arr2={{2,3,9,18,28},10,5};
struct Array *arr3;
arr3=Difference(&arr1,&arr2);
Display(*arr3);
return 0;
}