forked from sainirock61/CPP-Projects-Algos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortingarray.cpp
More file actions
144 lines (111 loc) · 3.47 KB
/
sortingarray.cpp
File metadata and controls
144 lines (111 loc) · 3.47 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include<iostream>
using namespace std;
int main()
{
int n,num[500],fun[500],a,m,k,full[1000];
cout<<"Enter the length of FIRST array :--";
while(!(cin>>n)|| (n<0))
{
cin.clear();
cin.ignore(100,'\n');
cout<<"INVALID INPUT. ENTER AGAIN:";
}
cout<<"Enter the terms of FIRST Array :-- "<<endl;
for(int i=0;i<n;i++)
{
cin>>num[i];
}
cout<<"\n\nEnter the length of SECOND array :--";
while(!(cin>>m)|| (m<0))
{
cin.clear();
cin.ignore(100,'\n');
cout<<"INVALID INPUT. ENTER AGAIN:";
}
cout<<"Enter the terms of SECOND Array :-- "<<endl;
for(int i=0;i<m;i++)
{
cin>>fun[i];
}
cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n";
cout<<" FIRST ARRAY IS:- [ ";
for(int x=0;x<n;x++)
{
cout<<num[x]<<" ";
}
cout<<" ]\n\n";
cout<<" SECOND ARRAY IS:- [ ";
for(int x=0;x<m;x++)
{
cout<<fun[x]<<" ";
}
cout<<" ]\n\n\n";
cout<<"_______________________________________________________________________________________________________________________\n";
cout<<" SORTING OF ARRAYS \n";
cout<<"_______________________________________________________________________________________________________________________\n";
//BUBBLE SORTING
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-1-i;j++)
{
if(num[j]>num[j+1])
{
int temp = num[j];
num[j] = num[j+1];
num[j+1] = temp;
}
}
}
cout<<"\n\n FIRST ARRAY AFTER SORTING :-- ";
for(int i=0;i<n;i++)
{
cout<<num[i]<<" ";
}
for(int i=0;i<m-1;i++)
{
for(int j=0;j<m-1-i;j++)
{
if(fun[j]>fun[j+1])
{
int temp = fun[j];
fun[j] = fun[j+1];
fun[j+1] = temp;
}
}
}
cout<<"\n\n SECOND ARRAY AFTER SORTING :-- ";
for(int i=0;i<m;i++)
{
cout<<fun[i]<<" ";
}
cout<<"\n\n";
cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n";
cout<<" MERGING OF ARRAYS \n";
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
int p=0,i=0,j=0;
while(i<n && j<m)
{
if(num[i]<fun[j])
{
full[p++]=num[i++];
}
else
{
full[p++]=fun[j++];
}
}
while(i<n)
{
full[p++]=num[i++];
}
while(j<m)
{
full[p++]=fun[j++];
}
cout<<"\n ARRAY AFTER MERGING :-- ";
for(i=0;i<n+m;i++)
{
cout<<full[i]<<" ";
}
cout<<"\n\n==================================================================================================================";
}