-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubblesorttemplate.cpp
More file actions
132 lines (71 loc) · 1.07 KB
/
Copy pathbubblesorttemplate.cpp
File metadata and controls
132 lines (71 loc) · 1.07 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
#include<iostream>
using namespace std;
template <class t>
class bubble
{
t a[25];
public:
void get(int);
void sort(int);
void display(int);
};
template <class t>
void bubble <t>::get(int n)
{
int i;
cout<<"\nEnter the array elements:";
for(i=0; i<n;i++)
cin>>a[i];
}
template <class t>
void bubble <t>::display(int n)
{
int i;
cout<<"\n The sorted array is…\n";
for(i=0;i<n;i++)
cout<<a[i];
}
template <class t>
void bubble <t>::sort(int n)
{
int i,j;
t temp;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
int main()
{
int n;
bubble<int> b1;
bubble<float> b2;
bubble<char> b3;
cout<<"\n Bubble Sort on Integer Values…";
cout<<"\n Enter the size of array:\n";
cin>>n;
b1.get(n);
b1.sort(n);
b1.display(n);
cout<<"\n Bubble Sort on Float Values…";
cout<<"\n Enter the size of array:\n";
cin>>n;
b2.get(n);
b2.sort(n);
b2.display(n);
cout<<"\n Bubble Sort on Integer Values…";
cout<<"\n Enter the size of array:\n";
cin>>n;
b3.get(n);
b3.sort(n);
b3.display(n);
return 0;
}