// Name: B6-24 // Date: 10/23/19 import java.io.*; //imports File import java.util.*; //imports Scanner public class Searches_Driver { private static int amount = 1325; public static void main(String[] args) throws Exception { String[] apple = input("declaration.txt"); Arrays.sort(apple); Scanner sc = new Scanner(System.in); while(true) { System.out.print("Enter a word: "); String target = sc.next(); //Liberty if(target.equals("-1") ) break; Searches.reset(); int found = Searches.linear(apple, target); if(found == -1) System.out.println(target + " was not found by the linear search."); else System.out.println("Linear Search found it at location "+found+" in " + Searches.getLinearCount()+" comparisons."); int found2 = Searches.binary(apple, target); if(found2 == -1) System.out.println(target + " was not found by the binary search."); else System.out.println("Binary Search found it at location "+found2+" in " + Searches.getBinaryCount()+" comparisons."); } } public static String[] input(String filename) throws Exception { Scanner infile = new Scanner( new File(filename) ); String[] array = new String[amount]; for (int k =0; k end) return -1; binaryCount++; int middle = start + (end - start) / 2; int comp = target.compareTo(array[middle]); if (comp == 0) return middle; else if (comp < 0) return binaryhelper(array, target, start, middle - 1); else if (comp > 0) return binaryhelper(array, target, middle + 1, end); return -1; } }