-
Notifications
You must be signed in to change notification settings - Fork 0
/
selection_sort.cpp
180 lines (153 loc) · 3.61 KB
/
selection_sort.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*Write A C++ Program Using Class Template For Selection Sort.*/
/*Name: Aditya Gade Class: SE-A Created:21/8/19 Last Modified:28/8/19*/
#include<iostream>
#include<iomanip>
#include"temp1.h"
using namespace std;
int main()
{
char ch;
cout<<"\nEnter the type in which you want to implement:\n1.Integer\t2.Char\t3.Float\t4.Double:"<<endl;
cin>>ch;
int n;
cout<<"\nEnter the size of array"<<endl;
cin>>n;
sort <int>s1(n);
sort <char>s2(n);
sort <float>s3(n);
sort <double>s4(n);
switch(ch)
{
case '1':
cout<<"\nINTEGER:";
cout<<"\nEnter the Elements"<<endl;
s1.input();
cout<<"\n\nARRAY BEFORE SORT:";
s1.display();
s1.selection_sort();
cout<<"\n\nARRAY AFTER SORT:";
s1.display();
break;
case '2':
cout<<"\nCHARACTER:";
cout<<"\nEnter the Elements"<<endl;
s2.input();
cout<<"\n\nARRAY BEFORE SORT:";
s2.display();
s2.selection_sort();
cout<<"\n\nARRAY AFTER SORT:";
s2.display();
break;
case '3':
cout<<"\nFLOAT:";
cout<<"\nEnter the Elements"<<endl;
s3.input();
cout<<"\n\nARRAY BEFORE SORT:";
s3.display();
s3.selection_sort();
cout<<"\n\nARRAY AFTER SORT:";
s3.display();
break;
case '4':
cout<<"\nDOUBLE:";
cout<<"\nEnter the Elements"<<endl;
s4.input();
cout<<"\n\nARRAY BEFORE SORT:";
s4.display();
s4.selection_sort();
cout<<"\n\nARRAY AFTER SORT:";
s4.display();
break;
default:
cout<<"\nINVALID INPUT!!!\nNow run the program again.";
break;
}
return 0;
}
/*
SAMPLE OUTPUT:
1.INTEGER:
kkw@kkw-HP-280-G2-MT-Legacy:~$ cd SEA19
kkw@kkw-HP-280-G2-MT-Legacy:~/SEA19$ g++ selection_sort.cpp
kkw@kkw-HP-280-G2-MT-Legacy:~/SEA19$ ./a.out
Enter the type in which you want to implement:
1.Integer 2.Char 3.Float 4.Double:
1
Enter the size of array
5
INTEGER:
Enter the Elements
5
1
4
2
3
ARRAY BEFORE SORT: 5 1 4 2 3
Next STEP: 1 5 4 2 3
Next STEP: 1 2 4 5 3
Next STEP: 1 2 3 5 4
Next STEP: 1 2 3 4 5
ARRAY AFTER SORT: 1 2 3 4 5kkw@kkw-HP-280-G2-MT-Legacy:~/SEA19$
2.CHARACTER:
kkw@kkw-HP-280-G2-MT-Legacy:~$ cd SEA19
kkw@kkw-HP-280-G2-MT-Legacy:~/SEA19$ g++ selection_sort.cpp
kkw@kkw-HP-280-G2-MT-Legacy:~/SEA19$ ./a.out
Enter the type in which you want to implement:
1.Integer 2.Char 3.Float 4.Double:
2
Enter the size of array
5
CHARACTER:
Enter the Elements
z
a
b
y
x
ARRAY BEFORE SORT: z a b y x
Next STEP: a z b y x
Next STEP: a b z y x
Next STEP: a b x y z
ARRAY AFTER SORT: a b x y zkkw@kkw-HP-280-G2-MT-Legacy:~/SEA19$
3.FLOAT
kkw@kkw-HP-280-G2-MT-Legacy:~$ cd SEA19
kkw@kkw-HP-280-G2-MT-Legacy:~/SEA19$ g++ selection_sort.cpp
kkw@kkw-HP-280-G2-MT-Legacy:~/SEA19$ ./a.out
Enter the type in which you want to implement:
1.Integer 2.Char 3.Float 4.Double:
3
Enter the size of array
5
FLOAT:
Enter the Elements
1.4
2.78
2.95
0.67
0.23
ARRAY BEFORE SORT: 1.4 2.78 2.95 0.67 0.23
Next STEP: 0.23 2.78 2.95 0.67 1
Next STEP: 0.23 0.67 2.95 2 1
Next STEP: 0.23 0.67 1 2 2
ARRAY AFTER SORT: 0.23 0.67 1.4 2.78 2.95kkw@kkw-HP-280-G2-MT-Legacy:~/SEA19$
4.DOUBLE:
kkw@kkw-HP-280-G2-MT-Legacy:~$ cd SEA19
kkw@kkw-HP-280-G2-MT-Legacy:~/SEA19$ g++ selection_sort.cpp
kkw@kkw-HP-280-G2-MT-Legacy:~/SEA19$ ./a.out
Enter the type in which you want to implement:
1.Integer 2.Char 3.Float 4.Double:
4
Enter the size of array
5
DOUBLE:
Enter the Elements
199.5
20000.65
2983.31
102.69
35647.2
ARRAY BEFORE SORT: 199.5 20000.7 2983.31 102.69 35647.2
Next STEP: 102.69 20000.7 2983.31 199 35647.2
Next STEP: 102.69 199 2983.31 20000 35647.2
ARRAY AFTER SORT: 102.69 199.5 2983.31 20000.65 35647.2kkw@kkw-HP-280-G2-MT-Legacy:~/SEA19$
*/