Assignment 10 on Chapter 19
Implement a searchFromLast( ) recursive method that looks at the last entry in the array instead of the first one. You may use the search( ) method shown below as a reference.
public static <T> boolean inArray(T[] anArray, T anEntry)
return search(anArray, 0, anArray.length – 1, anEntry);
// end inArray
private static <T> boolean search(T[] anArray, int first, int last, T desiredItem)
boolean found;
if (first > last)
found = false; // No elements to search
else if (desiredItem.equals(anArray[first]))
found = true;
else
found = search(anArray, first + 1, last, desiredItem);
return found;
// end search
What to submit:
- The ArraySearcher.java including the searchFromLast( ) method implementation
- The Driver.java file that tests the new method