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

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

二、阅读程序·第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;
        }
    }
}

程序的时间复杂度是( )。

{{ select(1) }}

  • Θ(nlog⁡n)\Theta(n\log n)
  • Θ(log⁡n)\Theta(\log n)
  • Θ(n)\Theta(n)
  • Θ(n2)\Theta(n^2)