1806. 珅泽教育CSP-J第一轮模拟考第九套 第 20 题

珅泽教育CSP-J第一轮模拟考第九套 第 20 题

二、阅读程序·第1题(选择题)

void solve(int n, int a[])
{
    while (true)
    {
        bool found = false;
        for (int i = 0; i + 1 < n; ++i)
        {
            if (a[i] > a[i+1])
            {
                found = true;
                int temp = a[i];
                a[i] = a[i + 1];
                a[i + 1] = temp;
            }
        }
        if (not found) {
            break;
        }
    }
}

当输入为 n=5,a = [3, 1, 4, 1, 5] 时,程序结束时,a=( )。

{{ select(1) }}

  • [1, 3, 1, 4, 5]
  • [5, 4, 3, 1, 1]
  • [1, 1, 3, 4, 5]
  • [3, 1, 4, 1, 5]