# include <iostream>
# include <algorithm>
using namespace std;
inline int findpivot(int *A, int i, int j)
{
return (i + j) / 2;
}
inline int Partition(int *A, int left, int right, int& pivot)
{
do
{
while(A[++left] < pivot);
while((left < right) && (pivot < A[--right]));
swap(A[left], A[right]);
}
while(left < right);
return left;
}
void qsort(int *A, int left, int right)
{
if(right<=left) return;
int pivotindex=findpivot(A,left,right);
swap(A[pivotindex],A[right]);
int k=Partition(A,left-1,right,A[right]);
swap(A[k],A[right]);
qsort(A,left,k-1);
qsort(A,k+1,right);
}
int main()
{
int n;
scanf("%d", &n);
int *a;
a = new int[n];
for(int i = 0; i < n; i++)
cin >> a[i];
qsort(a, 0, n - 1);
for(int i = 0; i < n; i++)
cout << a[i] << " ";
cout << endl;
return 0;
}
# include <iostream>
# include <algorithm>
using namespace std;
void mergesort(int *A, int *temp, int left, int right)
{
int mid=(left+right)/2;
if (left==right) return;
mergesort(A,temp,left,mid);
mergesort(A,temp,mid+1,right);
for(int i=left;i<=right;i++)
temp[i]=A[i];
int i1=left;
int i2=mid+1;
for(int curr=left;curr<=right;curr++){
if(i1==mid+1)
A[curr]=temp[i2++];
else if(i2>right)
A[curr]=temp[i1++];
else if(temp[i1]<temp[i2])
A[curr]=temp[i1++];
else A[curr]=temp[i2++];
}
}
int main()
{
int n;
scanf("%d", &n);
int *a, *temp;
a = new int[n];
temp = new int[n];
for(int i = 0; i < n; i++)
cin >> a[i];
mergesort(a, temp, 0, n - 1);
for(int i = 0; i < n; i++)
cout << a[i] << " ";
cout << endl;
return 0;
}
# include <iostream>
# include <algorithm>
using namespace std;
void inssort(int *A, int n, int incr)
{
for(int i = incr; i < n; i += incr)
for(int j = i; (j >= incr) && (A[j] < A[j - incr]); j -= incr)
swap(A[j], A[j - incr]);
}
void shellsort(int *A, int n)
{
for(int i=n/3;i>2;i/=3)
for(int j=0;j<i;j++)
inssort(&A[j],n-j,i);
inssort(A,n,1);
}
int main()
{
int n;
scanf("%d", &n);
int *a;
a = new int[n];
for(int i = 0; i < n; i++)
cin >> a[i];
shellsort(a, n);
for(int i = 0; i < n; i++)
cout << a[i] << " ";
cout << endl;
return 0;
}