Tuesday, 7 October 2014

Max. length of bitonic array.

Code for finding max. length of bitonic array.

int bitonic(int a[], int size){
 int maxLength = 0;
 int flag = 0, count = 1;
 for(int i= 0 ;i<size-1;i++){
  if(flag == 0){
   if(a[i]<=a[i+1]){
    count++;
   }else if(a[i]>a[i+1]){
    flag = 1;
    count++;
   }
  }
  else if(flag == 1){
   if(a[i]>=a[i+1]){
    count++;
   }else{
    flag = 0;
    maxLength = max(maxLength, (count));
    count = 2;
   }
  }
 }
 maxLength = max(maxLength, count);
 return maxLength;
}

No comments:

Post a Comment