forked from DEEZZU/Traditional-Cpp-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMYHEAD.H
75 lines (63 loc) · 843 Bytes
/
MYHEAD.H
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
65
66
67
68
69
70
71
72
73
74
75
/*funciton for union*/
#include<iostream.h>
#include<conio.h>
#define max 1024
void Union(int arr1[max],int arr2[max],int s1,int s2)
{
int U[max];
int i,j,k,s3;
k=0;
for(i=0,j=0;i<s1 && j<s2;)
{
if(arr1[i]>arr2[j])
{
U[k++]=arr2[j++];
}
else if(arr1[i]<arr2[j])
{
U[k++]=arr1[i++];
}
else
{
U[k++]=arr1[i++];
j++;
}
}//FOR
while(i<s1)
{
U[k++]=arr1[i++];
}
while(j<s2)
{
U[k++]=arr2[j++];
}
s3=k;//size of union
for(i=0;i<s3;i++)
cout<<U[i]<<" ";
}
void Intersection(int arr1[max],int arr2[max],int s1,int s2)
{
int I[max];
int i,j,k,s3;
k=0;
cout<<"\n Here";
for(i=0,j=0;i<s1 && j<s2;)
{
if(arr1[i]>arr2[j])
{
i++;
}
else if(arr1[i]<arr2[j])
{
j++;
}
else
{
I[k++]=arr1[i++];
j++;
}
}//FOR
s3=k;//size of interscetion
for(i=0;i<s3;i++)
cout<<I[i]<<" ";
}