Selection sort
Mon Nov 06 2023 21:39:36 GMT+0000 (Coordinated Universal Time)
Saved by
@70da_vic2002
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <iterator>
#include <algorithm>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#define endl "\n"
#define ll long long
#define all(v) v.begin(),v.end()
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N ;
cin>>N ;
ll X[N] ;
for(ll i=0 ;i<N ;i++){cin>>X[i];
}
ll Mn=X[0] ;
for(ll i=0 ;i<N-1 ;i++){
for(ll J=i ;J<N ;J++){
if(X[J]<Mn){
Mn=X[J] ;
swap(X[i],X[J]) ;
}
}
Mn=X[i+1] ;
}
for(ll i=0 ;i<N ;i++){
cout<<X[i]<<" ";
}
}
content_copyCOPY
https://www.onlinegdb.com/online_c++_compiler
Comments