Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to search element in sorted array using java

while(low<=high)
        {
            mid=low + ((high - low) / 2);;
 
            if(arr[mid]==number)
            {
                return mid;
            }
            if(arr[mid]<=arr[high])
            {
                // Right part is sorted
                if(number > arr[mid] && number <=arr[high])
                {
                    low=mid+1;
                }
                else
                {
                    high=mid-1;
                }
            }
            else
            {
                // Left part is sorted
                if(arr[low]<=number && number < arr[mid])
                {
                    high=mid-1;
                }
                else
                {
                    low=mid+1;
                }
            }
        }
        return -1;
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: imagebutton get background color programmatically 
Java :: JAVA Print Concatenated Strings 
Java :: java for loop example 
Java :: plot vector field in java 
Java :: ava program to add two numbers taking input from user 
Java :: mock ioexception mockito on BufferedReader 
Java :: JSP Convertir Int a String 
Java :: Calling constructor methods in java 
Java :: how do you rate yourself in java 
Java :: Read array of characters from space separated values in java 
Java :: how to get the width and height of display device in java 
Java :: How to center a print statement text? 
Java :: buffered reader for big integer 
Java :: java 8 anymatch two lists 
Java :: For loop in selenium java li 
Java :: java print line 
Java :: okhttpconfig 
Java :: first method in jdbc 
Java :: java window always on top 
Java :: jsp form upload file 
Java :: why use var in java 
Java :: null pointer exception during registering user to the firebase 
Java :: Which of the following is an example of a Method reference? 
Java :: concurrentskiplistset infinite loop in jdk 
Java :: issue wsdl call java example 
Java :: make a string bean spring xml 
Java :: setCookie("showPopupBannerBeta", 1, 1 
Java :: lighting strike solved 
Java :: amstrong 
Java :: executors java 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =