-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArray merging and reversing2.cpp
75 lines (70 loc) · 1.36 KB
/
Array merging and reversing2.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
#include<iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void Marge(int *t1,int *t2,int N);
void Reverse(int *M);
int main()
{
int s = 5;
int *p1 = new int[s];
int *t1 = p1;
cout<<"Enter the elements of first array\n";
for (int i=0; i<s; i++)
{
cin>>p1[i];
}
cout<<"First Array Elements: "<<endl;
for (int i=0; i<5; i++)
{
cout<<p1[i]<<" ";
}
cout<<endl<<endl;
t1 = p1;
//====================================
int *p2 = new int[s];
int *t2 = p2;
cout<<"Enter the elements of second array\n";
for (int i=0; i<s; i++)
{
cin>>p2[i];
}
cout<<"Second Array Elements:\n"<<endl;
for (int i=0; i<5; i++)
{
cout<<p2[i]<<" ";
}
cout<<endl;
t2 = p2;
cout<<endl<<"================ Marge Function ===============\n"<<endl;
Marge(t1,t2, s);
}
void Marge(int *t1,int *t2,int N)
{
int size = N*2;
int *Marge_elements = new int[size];
int *M = Marge_elements;
for (int i=0; i<size; i++)
{
Marge_elements[i] = *t1;
t1++;
i++;
Marge_elements[i] = *t2;
t2++;
}
for(int i=0; i<size; i++)
{
cout<<Marge_elements[i]<<" ";
}
M = Marge_elements;
cout<<endl;
cout<<endl<<"================ Reverse Function ===============\n"<<endl;
Reverse(M);
}
void Reverse(int *M)
{
for(int i=9; i>=0; i--)
{
cout<<M[i]<<" ";
}
}