[数据结构 学习]SM算法c++实现
int result[2];
int* SM(int* A, int n) {
int max, min;
int* SM(int* A, int n) {
int max, min;
max = min = A[0];
for (int i = 1; i < n; i++) {
if (A[i] > max) {
max = A[i];
}
if (A[i] < min) {
min = A[i];
}
}
//遍历并比较大小
if (A[i] > max) {
max = A[i];
}
if (A[i] < min) {
min = A[i];
}
}
//遍历并比较大小
result[0] = min;
result[1] = max;
return result;
result[1] = max;
return result;
//通过指针传递最大值和最小值
}
}