#include<iostream>
#include<vector>
using namespace std;
class solution
{
public:
void heaping(vector<int>& v, int i,int size)//在假设的基础上构建i节点为根节点的最大堆
{
if (i<size)
{
int left = 2 * i + 1;
int right = 2 * i + 2;
int largest=i;
if (left < size)
{
if (v[largest] < v[left])
largest = left;
}
if (right<size)
{
if (v[largest] < v[right])
largest = right;
}
if (largest != i)
{
int temp;
temp = v[i];
v[i] = v[largest];
v[largest] = temp;
heaping(v, largest, size);
}
}
}
void max_heaping(vector<int>& v,int size)
{
for (int i = size; i >=1; i--)//建最大堆就是对每个节点都建立最大建堆,构建的过程保证了课程中的假设
//因为是从子节点开始向上构造,子节点对应的子树是一种最大堆
{
heaping(v, i-1, size);
}
}
void heap_sort(vector<int>& v)
{
int size_o = v.size();
for (int i = size_o; i >= 1; i--)
{
max_heaping(v, i);
int temp = v[0];
v[0] = v[i-1];
v[i - 1] = temp;
}
}
};
int main()
{
int n;
cin >> n;
//vector<int> v(n);
vector<int> v;
for (int i = 0; i < n; i++)
{
int temp;
cin >> temp;
v.push_back(temp);
}
solution s;
s.heap_sort(v);
for (int i = 0; i < v.size(); i++)
{
cout << v[i];
}
return 0;
}
#include<vector>
using namespace std;
class solution
{
public:
void heaping(vector<int>& v, int i,int size)//在假设的基础上构建i节点为根节点的最大堆
{
if (i<size)
{
int left = 2 * i + 1;
int right = 2 * i + 2;
int largest=i;
if (left < size)
{
if (v[largest] < v[left])
largest = left;
}
if (right<size)
{
if (v[largest] < v[right])
largest = right;
}
if (largest != i)
{
int temp;
temp = v[i];
v[i] = v[largest];
v[largest] = temp;
heaping(v, largest, size);
}
}
}
void max_heaping(vector<int>& v,int size)
{
for (int i = size; i >=1; i--)//建最大堆就是对每个节点都建立最大建堆,构建的过程保证了课程中的假设
//因为是从子节点开始向上构造,子节点对应的子树是一种最大堆
{
heaping(v, i-1, size);
}
}
void heap_sort(vector<int>& v)
{
int size_o = v.size();
for (int i = size_o; i >= 1; i--)
{
max_heaping(v, i);
int temp = v[0];
v[0] = v[i-1];
v[i - 1] = temp;
}
}
};
int main()
{
int n;
cin >> n;
//vector<int> v(n);
vector<int> v;
for (int i = 0; i < n; i++)
{
int temp;
cin >> temp;
v.push_back(temp);
}
solution s;
s.heap_sort(v);
for (int i = 0; i < v.size(); i++)
{
cout << v[i];
}
return 0;
}