在函数执行过程中必须满足哪些条件?(断言)
我想确保我的断言能够在运行第 i 个循环后描述我所知道的真实情况。
int linearsearch(int arr[], int n, int target) {
for (int i = 0; i < n; i++) {
if (arr[i] == target) return i;
}
return -1;
}
这只是一个迭代线性搜索函数,如果找到目标,则返回目标的索引,否则返回 -1。
在函数执行过程中必须满足哪些条件?(断言)
我想确保我的断言能够在运行第 i 个循环后描述我所知道的真实情况。
int linearsearch(int arr[], int n, int target) {
for (int i = 0; i < n; i++) {
if (arr[i] == target) return i;
}
return -1;
}
这只是一个迭代线性搜索函数,如果找到目标,则返回目标的索引,否则返回 -1。