2022-11-14 04:20发布
代码:#includeint main(){int arr[10]={0};int i=0;int max=0;int min=0;print
MaxMin(const int * data,int size,int&max,int&min)
{
if(0 == size%2)
if(data [0] ) 一次取2个数比较大和和max比小的和min比> data [1])
max = data [0];
min = data [1];
} else
min = data [0];
max = data [1];
}
int i = 2;
while(i <size)
if(data [i]> data [i + 1])
max = max> data [i]?max:data [i];
min = min <data [i + 1]?min:data [i + 1];
max = max> data [i + 1]?max:data [i + 1];
min = min <data [i]?min:data [i];
i + = 2;
最多设置5个标签!
MaxMin(const int * data,int size,int&max,int&min)
{
if(0 == size%2)
{
if(data [0] ) 一次取2个数比较大和和max比小的和min比> data [1])
{
max = data [0];
min = data [1];
} else
{
min = data [0];
max = data [1];
}
} else
{
min = data [0];
max = data [0];
}
int i = 2;
while(i <size)
{
if(data [i]> data [i + 1])
{
max = max> data [i]?max:data [i];
min = min <data [i + 1]?min:data [i + 1];
} else
{
max = max> data [i + 1]?max:data [i + 1];
min = min <data [i]?min:data [i];
}
i + = 2;
}
}
一周热门 更多>