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

程序填空题:The Smallest Missing Integer

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

```c++
int MissingMin( int a[], int n )
{
int i, j, min, missing=1;

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

```






答案:
第1空:a[j]
第2空:break

发表评论

访客

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