import java.util.Random; /** * Tests the searching and sorting methods * * @author alchambers * @version Fall 2015 */ public class Tester { private static void printArray(int[] array){ String printStr = "["; int i; for(i = 0; i < array.length-1; i++){ printStr += array[i] + ", "; } printStr += array[i] + "]"; System.out.println(printStr); } public static void main(String[] args){ int[] array1 = {1, -28, 67, 81, 3, 25, -82, 21}; int[] array2 = {49, 0, 69, -47, 14, 69, -20, 61}; System.out.println("===== Linear search ====="); printArray(array1); System.out.println(); System.out.print("Searching for 25: "); System.out.println(Searching.linearSearch(array1, 25)); System.out.print("Searching for 100: "); System.out.println(Searching.linearSearch(array1, 100)); System.out.println(); System.out.println("===== Selection sort ====="); System.out.print("Before sorting:"); printArray(array1); System.out.print("After sorting:"); Sorting.selectionSort(array1); printArray(array1); System.out.println(); System.out.println("===== Binary search ====="); printArray(array1); System.out.print("Searching for 25: "); System.out.println(Searching.binarySearch(array1, 25)); System.out.print("Searching for 100: "); System.out.println(Searching.binarySearch(array1, 100)); System.out.println(); System.out.println("===== Bubble sort ====="); System.out.print("Before sorting:"); printArray(array2); System.out.print("After sorting:"); Sorting.bubbleSort(array2); printArray(array2); System.out.println(); } }