CSCI 180/181 Lab 8

handin name for today's lab is lab8 The lab is due on 14 March 2008 at 23:59. You must use good style and comments, as usual.

Objectives

Complete the Search class and SearchTester begun in class today. Parts to this include:

  1. Tests from the doc we came up with in class as well as any other tests that you deem necessary
  2. Correct versions of algorithms findLargest, binarySearch, sequentialSearch
Write the tests first and then correct my algorithms. Here are the algorithms:
public int findLargest(int [] array){
    int lsf = array[0];
    for (int i=1; i <= array.length; i++){
        if (array[lsf] > lsf){
           lsf = array[lsf];
        }
    }
    return lsf;
}

public int sequentialSearch(int [] array, int target){
    int result=0;
    for (int i=1; i <= array.length; i++){
        if (i == target){
           result = i;
        }
    }
    return result;
}

public int binarySearch(int [] array, int target){
    int result=0;
    int start=0; 
    int finish = array.length-1;
    while (start < finish){
        int mid = (start+finish) / 2
        if (target == array[mid]) {
	   return array[mid];
        } else {
          if (target < list[mid]) {
             start = mid+1
          }
          else {
             finish = mid-1
          }
        }
    return result;
}