Thursday, September 29, 2022

C++ Code A sorted array rotated find the the point from where it is rotated

  A sorted array rotated find the the point from where it is rotated


C ++ Code

#include <iostream>

using namespace std;


int find(int a[],int n)

{

     int low=0,up=n;

     int mid;

     while(low<=up)

     {

           mid=(up+low)/2;

           if(a[mid]<a[mid-1]&&a[mid]<a[mid+1])

              return a[mid];

           else if(a[mid]>a[low])

           low=mid+1;

           else

           up=mid-1;

    

     }

     return 0;

}

int main()

{

     int a[]={14,16,18,2,3,4,5,6};

     int num=find(a,7);

     printf("%d",num);

    

     return 0;

 }




Output :


2



1 comment:

  1. All the contents you mentioned in post is too good and can be very useful. I will keep it in mind, thanks for sharing the information keep updating, looking forward for more posts.
    Cricut doodles shape USA

    ReplyDelete