-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselection sort.cpp
49 lines (35 loc) · 957 Bytes
/
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
#include<iostream>
//#include<limits>
using namespace std;
template<class T>
T selection_sort() //Template function
{
T a[10];
T temp;
for(int i=0;i<10;i++) //Accepting elements
{
cout<<"a["<<i<<"]=";
cin>>a[i];
}
for(int i=0;i<10;i++) //Sorting logic
{
for(int j=i+1;j<10;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(int i=0;i<10;i++) //Displaying logic
{
cout<<a[i]<<"\n";
}
}
int main()
{
cout<<"Enter array elements for sorting \n";
selection_sort<int>();
}