This preview shows page 1. Sign up to view the full content.
Unformatted text preview: if (channelArray[i].getName().compareTo(channelName) > 0) { System.out.println("Number of array cells examined: " + (i+1)); return channelArray[i].getNumber(); } } // Whole array was examined and channel was not there System.out.println("Number of array cells examined: " + numChannels); return 1; } 3. public int search2(String channelName) { // Precondition: Channel names are sorted in channelArray in increasing order. int min = 0; int max = numChannels1; int mid = 0; boolean found = false; int cellsExamined = 0; while (!found && min <= max) { mid = (min + max) / 2; cellsExamined++; if (channelArray[mid].getName().equals(channelName)) found = true; else if (channelName.compareTo(channelArray[mid].getName()) < 0) max = mid  1; else min = mid + 1; } System.out.println("Number of array cells examined: " + cellsExamined); if (found) return channelArray[mid].getNumber(); else return 1; }...
View
Full
Document
This note was uploaded on 12/19/2009 for the course CS 121 taught by Professor Reidmiller during the Spring '09 term at Carnegie Mellon.
 Spring '09
 ReidMiller

Click to edit the document details