// Name: // Lab: 3// CS 136 Spring 2000import structure.*;  // see http://www.cs.williams.edu/~bailey/JavaStructures/documentation.htmlimport java.util.Random;	// will need a random number generatorpublic class Search{	// pre: 	// post: returns the position 	//       of the first occurrence of x if x is in the array A 	//       and -1 otherwise	public static int linearSearch (int[] A, int x)	{   		int i;   		for (i = 0; (i < A.length) && (x != A[i]); i++);   		if (i == A.length)      		return -1;   		else      		return i;	}	// pre: the array A is sorted in non-decreasing order	// post: returns the position	// 	     of the first occurrence of x if x is in the array A	//       and -1 otherwise	public static int binarySearch (int[] A, int left, int right, int x)	{   		if (left >= right)     	{     		int compare = (left + right)/2;    	  	if (x == A[compare])     	    	return compare;    	  	else      	   		return -1;     	}   		else      	{         	int mid = (left + right) / 2;         	if (x == A[mid])            	return mid;         	else            	if (x < A[mid])               		return binarySearch (A, left, mid-1, x);            	else               		return binarySearch (A, mid+1, right, x);      	}	}	public static void main(String args[])	{   		System.out.println("Test your search algorithms thoroughly.  Try these and more...");   		int[] a = {1,3,6,8,10,13,15,20,24,26,29,46,50};   		System.out.println(" 26 was fount at: " + linearSearch(a, 26));   		System.out.println(" 26 was fount at: " +                               binarySearch(a, 0, a.length-1, 26));                                       System.out.println(" 1 was fount at: " + linearSearch(a, 1));   		System.out.println(" 1 was fount at: " +                               binarySearch(a, 0, a.length-1, 1));                                       System.out.println(" 50 was fount at: " + linearSearch(a, 50));   		System.out.println(" 50 was fount at: " +                               binarySearch(a, 0, a.length-1, 50));                                       System.out.println(" 0 was fount at: " + linearSearch(a, 0));   		System.out.println(" 0 was fount at: " +                               binarySearch(a, 0, a.length-1, 0));                                       System.out.println(" 52 was fount at: " + linearSearch(a, 52));   		System.out.println(" 52 was fount at: " +                               binarySearch(a, 0, a.length-1, 52));	}}