Tuesday, 7 October 2014

Simplified version of max length of bitonic array.

This is the variation of same type of code written below, but much more simplified version.


int func(int arr[], int n)
{
        int max=0;
        int i, inc=1, dec=0;
        for( i=2; i<n; i++)
        {
                if ( arr[i]< arr[i-1])
                        dec++;
                else if ( dec>0)
                {
                        if( inc +dec >max)
                                max = inc+ dec;
                        dec=0;
                        inc =2;
                }
                else
                        inc ++;

        }
            if( inc +dec >max)
                                max = inc+ dec;

        return max;
}

No comments:

Post a Comment