[求助]程序编译通不过
我认为最基本的high-low=1就不对,这样mid会出现负数,一直减下去永远也不会有结果/*请问大狭这个程序为什么在Turbo C2.0上编译通不过,而在VC++6.0就能通过*/
/*另外我还想问问如何在VC++6.0下对程序单步运行,以及查看每一不运行的结果以便查错*/
#include <stdio.h>
struct point
{
int x;
int y;
};
point MinMax(int A[],int low,int high)/*请问为什么显示语法错误Declaration syntax error*/
{
point p,p1,p2;
int mid;
if((high -low) == 1)
{
if(A[high] > A[low])
{
p.x = A[low];
p.y = A[high];
return p;
}
else
{
p.x = A[high];
p.y = A[low];
return p;
}
}
else
{
mid = (high - low)/2;
p1 = MinMax(A, low, mid);/*会永远减下去*//*mid=1,0,-1,-1,...*/
p2 = MinMax(A, mid+1, high);
if(p1.x > p2.x)
{
p.x = p2.x;
}
if(p1.x < p2.x)
{
p.x = p1.x;
}
if(p1.y > p2.y)
{
p.y = p1.y;
}
if(p1.y < p2.y)
{
p.y = p2.y;
}
return p;
}
}
main()
{
point p3;
int a[10]={1,23,24,1,6,23,34,2,54,6};
p3 = MinMax(a,2,5);/*实参给定2,5*/
printf("%d\n",p3.x);
printf("%d\n",p3.y);
}