-
Notifications
You must be signed in to change notification settings - Fork 0
/
genric.cpp
83 lines (80 loc) · 1.8 KB
/
genric.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
#include <iostream>
#include <cstdlib>
using namespace std;
const int SIZE = 10;
template <class T>
class sort
{
public:
T a[SIZE];
T &operator[](int i)
{
if (i < 0 || i > SIZE - 1)
{
cout << "\nIndex value of ";
cout << i << " is out-of-bonds.\n";
exit(1);
}
return a[i];
}
sort() {}
void read(int z)
{
for (int i = 0; i < z; i++)
cin >> a[i];
}
void disp(int z)
{ cout<<"{ ";
for (int i = 0; i < z; i++)
cout << a[i] << " ";
cout << "}\n";
}
template <class X>
void bubble(X *items, int count)
{
int a, b;
X t;
for (a = 1; a < count; a++)
{
for (b = count - 1; b >= a; b--)
{
if (items[b - 1] > items[b])
{
t = items[b - 1];
items[b - 1] = items[b];
items[b] = t;
}
}
}
}
};
int main()
{
sort<int> intob;
sort<double> doubleob;
int i, m, n;
cout << "\nEnter the size of integer array : ";
cin >> n;
cout << "\nEnter the size of double array : ";
cin >> m;
intob[n - 1] = 0;
doubleob[m - 1] = 0;
//taking input
cout << "\nEnter the elemnets of integer array-\n";
intob.read(n);
cout << "\nEnter the elements of double array-\n";
doubleob.read(m);
//displaying
cout << "\nUnsorted integer array is : ";
intob.disp(n);
cout << "\nUnsorted double array is : ";
doubleob.disp(m);
intob.bubble(intob.a, n);
doubleob.bubble(doubleob.a, m);
//Sorting
cout << "\nSorted integer array is : ";
intob.disp(n);
cout << "\nSorted double array is : ";
doubleob.disp(m);
return 0;
}