我正在尝试学习 Big O 表示法,但我对这个 C++ 代码有点困惑:
void enterElements(int *s1, int s1Size)
{
    for(int x = 0;x < s1Size;++x)
    {
    retry:
        cout<<"Element "<<x + 1<<": ";
        cin>>s1[x];
        int valid = validation();
        if(valid == 1)
        {
            cout<<"The input must be numbers."<<endl;
            goto retry;
        }
    }
}
因为我不知道如何做好,所以我得到了 3 个结果:
- 9n + 1 -> O(n)
 - 7nm + 2m + 2n + 1 -> O(nm)
 - 7n^2 + 4n + 1 -> O(n^2)
 
这些是正确的吗?如果没有,你能帮我找到正确的答案吗?
int validation()
{
int validation = 0;
if(cin.fail())
{
    validation = 1;
    cin.clear();
    cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
}
else
    validation = 0;
return validation;
}