-
Notifications
You must be signed in to change notification settings - Fork 0
/
16(merging two arrays).cpp
85 lines (78 loc) · 1.47 KB
/
16(merging two arrays).cpp
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
76
77
78
79
80
81
82
83
84
85
#include<iostream>
using namespace std;
class array
{
int *arr;
int *arr1;
int n;
int t;
int i;
public:
void makearr()
{
cout<<"enter the no of elements you wantr to enter";
cin>>n;
arr= new int[n];
for(i=0;i<n;i++)
{
cin>>arr[i];
}
}
/* void asc(int ar[],int x)
{
int temp;
n=x;
for(i=0;i<n-1;i++)
{
if(ar[i+1]<ar[i])
{
temp=arr[i];
ar[i]=ar[i+1];
ar[i+1]=temp;
}
}
for(i=0;i<n;i++)
{
cout<<ar[i]<<endl;
}
}*/
void merge(array &o)
{
array t3;
t3.arr=new int[n+o.n];
t=n+o.n;
for(i=0;i<t;i++)
{
if(i<n)
{
t3.arr[i]=arr[i];
}
if(i>=n)
{
t3.arr[i]=o.arr[i-n];
}
}
int temp;
// cout<<o.arr[]
for(i=0;i<t-1;i++)
{
if(t3.arr[i+1]<t3.arr[i])
{
temp=t3.arr[i];
t3.arr[i]=t3.arr[i+1];
t3.arr[i+1]=temp;
}
}
for(i=0;i<t;i++)
{
cout<<t3.arr[i]<<endl;
}
}
};
int main()
{
array t1,t2;
t1.makearr();
t2.makearr();
t1.merge(t2);
}