//冒泡
#include<iostream>
using namespace std;
const int N =100010;
int q[N],n;
void bubble_sort(){
for(int i=0;i<n;++i)
for(int j=0;j<n-i-1;++j)
if(q[j+1]<q[j]) swap(q[j],q[j+1]);
}
int main(){
cin>>n;
for(int i=0;i<n;++i)cin>>q[i];
bubble_sort();
for(int i=0;i<n;++i)cout<<q[i]<<" ";
return 0;
}
//插入
#include<iostream>
using namespace std;
const int N=100010;
int q[N],n;
void insert_sort(){
for(int i =0;i<n-1;++i){
int end=i;
int tmp = q[end+1];
while(end>=0){
if(tmp<q[end]){
q[end+1] = q[end];
end--;
}
else break;
}
q[end+1]=tmp;
}
}
int main(){
cin>>n;
for(int i=0;i<n;++i)cin>>q[i];
insert_sort();
for(int i=0;i<n;++i)cout<<q[i]<<" ";
return 0;
}
//选择排序
#include<iostream>
using namespace std;
const int N =100010;
int q[N],n;
void select_sort(){
int b=0, e=n-1;
while(b<e){
int max =b,min =b;
for(int i =b;i<e;++i){
if(q[i]>q[max]) max=i;
if(q[i]<q[min]) min=i;
}
swap(q[b],q[min]);
if(b==max)
max=min;
swap(q[e],q[max]);
++b;
--e;
}
}
int main(){
cin>>n;
for(int i=0;i<n;++i)cin>>q[i];
select_sort();
for(int i=0;i<n;++i)cout<<q[i]<<" ";
return 0;
}
//快排
#include<iostream>
using namespace std;
const int N=100010;
int q[N],n;
void quick_sort(int l,int r){
if(l>=r)return;
int i=l-1, j=r+1,x=q[l+r >>1];
while(i<j){
do ++i; while(q[i]<x);
do --j; while(q[j]>x);
if(i<j) swap(q[i],q[j]);
}
quick_sort(l,j);
quick_sort(j+1,r);
}
int main(){
cin>>n;
for(int i=0;i<n;++i) cin>>q[i];
quick_sort(0,n-1);
for(int i=0;i<n;++i) cout<<q[i]<<" ";
return 0;
}
//归并排序
#include<iostream>
using namespace std;
const int N=100010;
int q[N],n,tmp[N];
void merge_sort(int l,int r){
if(l>=r) return;
int mid = l+r>>1;
merge_sort(l,mid);
merge_sort(mid+1,r);
int k=0;
int i=l,j=mid+1;
while(i<=mid && j<=r){
if(q[i]<q[j])tmp[k++]=q[i++];
else tmp[k++]=q[j++];
}
while(i<=mid)tmp[k++]=q[i++];
while(j<=r)tmp[k++]=q[j++];
for(int i=0,j=l;j<=r;++i,++j) q[j]=tmp[i];
}
int main(){
cin>>n;
for(int i=0;i<n;++i)cin>>q[i];
merge_sort(0,n-1);
for(int i=0;i<n;++i)cout<<q[i]<<" ";
return 0;
}
//堆排序
#include<iostream>
using namespace std;
const int N =100010;
int q[N],n,m;
void down(int i){
int t = i;
if(i*2<=n && q[t]>q[i*2]) t=i*2;
if(i*2+1<=n && q[t]>q[i*2+1]) t = i*2+1;
if(i!=t){
swap(q[i],q[t]);
down(t);
}
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;++i)cin>>q[i];
for(int i=n/2;i>=1;--i){
down(i);
}
while(m--){
cout<<q[1]<<" ";
q[1]=q[n--];
down(1);
}
return 0;
}