-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselection.txt
68 lines (59 loc) · 1.31 KB
/
selection.txt
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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define vi vector<int>
#define vll vector<long long>
#define mp make_pair
#define MPII map<int,int>
#define MPLL map<long long,long long>
#define MPSI map<string,int>
#define MPIS map<int,string>
#define PRII pair<int,int>
#define PRLL pair<long long,long long>
#define SP cout<<fixed<<setprecision(10);
#define rep(i,inval,n) for(int i = inval; i < n; i++)
#define all(x) x.begin(),x.end()
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
void selection_sort(int arr[],int n)
{
int temp,min_ind,i,j;
for(i=0;i<n;i++)
{
min_ind=i;
for(j=i+1;j<n;j++)
{
if(arr[j]<arr[min_ind])
{
min_ind=j;
}
}
if(min_ind!=i)
{
temp=arr[i];
arr[i]=arr[min_ind];
arr[min_ind]=temp;
}
}
}
int main()
{
IOS;
int t=1;
// cin>>t;
while(t--)
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++) cin>>arr[i];
selection_sort(arr,n);
for(int i=0;i<n;i++) cout<<arr[i]<<" ";
cout<<endl;
}
return 0;
}