Согласно логике, предложенной Жаном-Бернаром Пеллереном
(в этом коде найдено только максимальное значение)
public class max_in_increasing_decreasing_array
{
public static int max (int a,int b,int c)
{
int maxi=-1;
if(a>maxi)
maxi=a;
if(b>maxi)
maxi=b;
if(c>maxi)
maxi=c;
return maxi;
}
public static void chkmax(int a[],int low,int high)
{
int mid=(low+high)/2;
if(low==high)
{
System.out.println(a[low]);
return;
}
if(low+1==high)
{
System.out.println(max(a[low],a[high],-1));
return;
}
if((a[mid-1]< a[mid]) && (a[mid] < a[mid+1]))
{
chkmax(a, mid+1, high);
}
else if((a[mid-1]> a[mid]) && (a[mid] > a[mid+1]))
{
chkmax(a, low, mid-1);
}
else
System.out.println(max(a[mid-1],a[mid],a[mid+1]));
}
public static void main(String[] args)
{
int a[]={6,7,4,3,2,1};
chkmax(a, 0,a.length-1);
}
}