A variant of the binary method
Package Level4;/*** Search in Rotated Sorted Array ** Suppose a sorted array is rotated at some unknown to you beforehand. ** (I. e ., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2 ). ** You are given a target value to search. if found in the array return its * index, otherwise return-1. ** You may assume no duplicate exists in the array. **/public class S33 {public static void main (String [] args) {int [] A = {2, 3, 4, 5, 6, 0, 1 }; system. out. println (search (A, 0);} public static int search (int [] A, int target) {return rec (A, target, 0,. length-1);} // recursive search for public static int rec (int [] A, int target, int low, int high) {if (low> high) {// return-1;} int mid = low + (high-low)/2; if (A [mid] = target) {// return mid;} int res = rec (A, target, low, mid-1) is found; // search for if (res =-1) on the left) {// if not found on the left, continue to search for res = rec (A, target, mid + 1, high);} return res ;}} on the right ;}}