Change the implementation of the following method so that it returns the index of element found in the search if the sea
Posted: Thu Jul 14, 2022 2:12 pm
Change the implementation of the following method so that it returns the index of element found in the search if the search is successful and returns -belongsAt-1 if not successful where belongsAt is the index where the element has to be inserted in the array so that the array remains sorted. private static < T extends Comparable < ? super T>> boolean binarySearch(T[] anArray, int first, int last, T desiredltem) boolean found; int mid = first + (last − first )/2; if (first > last) found = false; else if (desiredltem.equals(anArray[mid])) found = true; else if (desiredltem.compareTo(anArray[mid ]<0 ) found = binarySearch(anArray, first, mid - 1, desiredltem); else found = binarySearch(anArray, mid + 1, last, desiredltem); return found; \} // end binarySearch public static < T extends ComparableT>> boolean inArray (T anEntry ) \{ return binarySearch(anArray, 0, anArray.length - 1, anEntry); \}// end inArray