DAY44

 DAY44_第1张图片

#include 

using namespace std;


struct stu
{
private:
    int grade[100];
private:
    int num = setNum();
public:
    int setNum()
    {
        cout << "学生的数量为: ";
        cin >> num;
        return num;
    }
public:
    void input()
    {
        for(int i = 0; i < num; i++)
        {
            cin >> grade[i];
        }
    }
public:
    void sort()
    {
        for(int i = 1; i < num; i++)
        {
            for(int j = 0; j < num - i; j++)
            {
                if(grade[j] > grade[j + 1])
                {
                    int tmp = grade[j];
                    grade[j] = grade[j + i];
                    grade[j + 1] = tmp;
                }
            }
        }
    }
public:
    void show()
    {
        for(int i = 0; i < num; i++)
        {
            cout << grade[i] << ' ';
        }
        cout << endl;
    }
};


int main()
{
    stu s;
    s.setNum();
    s.input();
    s.sort();
    s.show();
    return 0;
}

你可能感兴趣的:(算法,数据结构)