//算法一:依次扫描,分别找出A[x1]和A[x2]
void max2_1(int A[], int lo, int hi, int &x1, int &x2) //1 < n = hi - lo
{
for(int i = lo + 1, x1 = lo; i < hi; i++) //扫描A[lo,hi),找出A[x1]
{
if(A[x1] < A[i])
x1 = i; //hi-lo-1=n-1
}
int x2L = lo;
int x2R = 0;
int t = x1;
for(int i = lo + 1; i < t; i++) //扫描A[lo,x1)
{
if(A[x2L] < A[i])
x2L = i; //x1-lo-1
}
for(int i = t + 1; i < hi; i++) //扫描A[x1,hi)
{
if(A[x2R] < A[i])
x2R = i; //hi-x1-1
}
x2 = (x2L > x2R) ? x2L : x2R;
}
int main()
{
int a[9] = {2,3,7,8,9,5,4,6,1};
max2_1(a, 1, 6, x1, x2);
cout << x1 << " " << x2 << endl;
return 0;
}
这是一个在数组中找最大两个数的简单程序。在函数max2_1中int t = x1 在debug时,x1 =4, t却一直为0,请问这是为什么