-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion03.cpp
107 lines (102 loc) · 2.24 KB
/
question03.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Input array size: ";
cin >> n;
int array[n];
cout << "Input array element: ";
for (int i = 0; i < n; i++)
{
cin >> array[i];
}
int count = 0, k = 0;
int assd[n];
for (int i = 0; i < n; i++)
{
if (array[i] % 2 == 0)
{
count++;
assd[k] = array[i];
k++;
}
}
int found = 0, l = 0;
int diss[n];
for (int i = 0; i < n; i++)
{
if (array[i] % 2 != 0)
{
found++;
diss[l] = array[i];
l++;
}
}
for (int i = 0; i < count - 1; i++)
{
int min = i;
for (int j = i + 1; j < count; j++)
{
if (assd[j] < assd[min])
{
min = j;
}
if (min != i)
{
swap(assd[i], assd[min]);
// int temp = assd[min];
// assd[min] = assd[i];
// assd[i] = temp;
}
}
}
for (int i = 0; i < found - 1; i++)
{
int min = i;
for (int j = i + 1; j < found; j++)
{
if (diss[j] > diss[min])
{
min = j;
}
if (min != i)
{
swap(diss[i], diss[min]);
// int temp = assd[min];
// assd[min] = assd[i];
// assd[i] = temp;
}
}
}
cout << "Assending Array is: ";
for (int i = 0; i < count; i++)
{
cout << assd[i] << " ";
}
cout << endl;
cout << "Dissending Array is: ";
for (int i = 0; i < found; i++)
{
cout << diss[i] << " ";
}
// cout << count;
// cout << found;
cout << endl;
int farr[count + found];
for (int i = 0; i < count; i++)
{
farr[i] = assd[i];
}
for (int i = 0; i < found; i++)
{
farr[i + count] = diss[i];
}
cout << "Finall Array is: ";
for (int i = 0; i < (count + found); i++)
{
cout << farr[i] << " ";
}
cout << endl;
main();
}