From fc59e8842076c96359445efbae44347c5bf0d621 Mon Sep 17 00:00:00 2001 From: "Udaya Krishnan.M" <101326005+UdayaKrishnanM@users.noreply.github.com> Date: Tue, 31 Jan 2023 02:09:56 +0530 Subject: [PATCH] Create order-agnostic-binary-search.java --- .../order-agnostic-binary-search.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 algorithms/Java/searching/order-agnostic-binary-search.java diff --git a/algorithms/Java/searching/order-agnostic-binary-search.java b/algorithms/Java/searching/order-agnostic-binary-search.java new file mode 100644 index 00000000..9e850cd0 --- /dev/null +++ b/algorithms/Java/searching/order-agnostic-binary-search.java @@ -0,0 +1,47 @@ +/* + Order Agnostic Binary Search is a method of finding the sorting in either ascending or descending order. +*/ + +public class OrderAgnosticBS { + public static void main(String[] args) { + int[] arr={1,2,3,4,5,6,7,8,9}; + int target=7; + int ans=orderAgnosticBS(arr,target); + System.out.println(ans); + } + static int orderAgnosticBS(int[] arr,int target){ + int start=0; + int end=arr.length-1; + //find array is sorted in ascending or descending order + boolean isAsc;// boolean isAsc = arr[start]target) { + end=mid-1; + } + else if(arr[mid]target){ + start=mid+1; + } + } + } + return -1; + } +}