Assignment 10

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;


found = search(anArray, first + 1, last, desiredItem);

return found;

// end search

What to submit:

  1. The including the searchFromLast( ) method implementation
  2. The file that tests the new method

Leave a Reply

Your email address will not be published. Required fields are marked *