-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselection_sort.cpp
More file actions
47 lines (35 loc) · 834 Bytes
/
selection_sort.cpp
File metadata and controls
47 lines (35 loc) · 834 Bytes
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
#include<iostream>
using namespace std;
int main()
{
int a[20],i,j,size,temp, loc,min;
cout<<"enter the size of an array : "<<endl;
cin>>size;
cout<<"enter the elements : "<<endl;
for(i=0;i<size;i++)
{
cin>>a[i];
}
for(i=0; i<(size-1) ; i++ )
{
min= a[i];
loc=i;
for(j=i+1 ;j<size ; j++)
{
if(a[j]<min)
{
min=a[j];
loc=j;
}
}
temp=a[i];
a[i]= a[loc];
a[loc]=temp;
}
cout<<"elements after selection sorting : " ;
for(i=0 ; i<size ; i++)
{
cout<< " " <<a[i];
}
return 0;
}