不需要排序,在读入的过程中维护好最大最小值就行了

#include <iostream>
using namespace std;

int main()
{
    int n, tmp;
    while (cin >> n)
    {
        int MAX = -0x3f3f3f3f, MIN = 0x3f3f3f3f;
        for (int i = 0; i < n; ++i)
        {
            cin >> tmp;
            if (tmp > MAX)
                MAX = tmp;
            if (tmp < MIN)
                MIN = tmp;
        }
        cout << MAX << " " << MIN << endl;
    }
    return 0;
}