forked from hacktoberfest17/programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselection.cpp
More file actions
55 lines (51 loc) · 839 Bytes
/
selection.cpp
File metadata and controls
55 lines (51 loc) · 839 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
48
49
50
51
52
53
54
55
#include < iostream >
using namespace std;
#define max 1000
int enter(int a[max],int n)
{
for( int i=0;i<n;i++)
{
cin>>a[i];
}
return 0;
}
int display( int a [max],int n)
{
for( int i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
return 0;
}
int S_sort( int a[max] , int n)
{
for( int i=0;i<n-1;i++)
{
int p=i;
for( int j=i+1;j<n;j++)
{
if(a[j]<a[p])
p=j;
}
if(p!=i)
{
int t=a[p];
a[p]=a[i];
a[i]=t;
}
}
return 0;
}
int main()
{ int n;
cout<<"Enter the size of the array: ";
cin>>n;
int a[max];
cout<<"Enter the contents of the array....";
enter (a,n);
S_sort(a,n);
cout<<"\nThe sorted array is....";
display(a,n);
cout<<endl;
return 0;
}