使用C++标准库

#include<iostream>
#include<vector>
#include<algorithm>

int main(int argc, char const *argv[])
{
    int n = 0, tmp = 0;
    std::vector<int> v;
    int is_asc = 0;
    std::cin >> n;

    for (int i = 0; i < n; i++)
    {
        std::cin >> tmp;
        v.push_back(tmp);
    }
    
    std::cin >> is_asc;

    if (is_asc)
    {
        std::sort(v.begin(), v.end(), [](int a, int b)->bool{ return a > b; });
    }
    else
    {
        std::sort(v.begin(), v.end());
    }
    
    for (auto it : v)
    {
        std::cout << it << " ";
    }
    

    return 0;
}