-->
当前位置:首页 > 题库 > 正文内容

程序填空题:The Largest Missing Integer

Luz4年前 (2021-05-10)题库652
Given an array `a[]`of `n` integers, the function `MissingMax` is to find and return the maximum negative integer which is **NOT** in the array. For example, given { -3, -1, 8, 1, 0 }, -2 is the largest negative integer which is missing.

```c++
int MissingMax( int a[], int n )
{
int i, j, max, missing = -1;

for( i=0; i max = i;
for( j = i+1; j < n; j++ )
if (@@[a[j]>a[max]](3)) max = j;
if ( max != i ) swap(a[i], a[max]);
if ( a[i] == missing ) missing--;
else if ( a[i] < missing ) @@[break](3);
}
return missing;
}

```






答案:
第1空:a[j]>a[max]

第2空:break

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。