#include #include int *a; int generateRandom(minRange,maxRange) int minRange,maxRange; { /* returns integer in range minRange <= x <= maxRange*/ return minRange+abs(rand()) % (maxRange-minRange+1); } int intCompare(const void* xin, const void* yin) { int *x,*y; x=(int*) xin; y=(int*) yin; return (*x) - (*y); } int intSearch(const void* keyIn, const void* arrayMemberIn) { int *key,*arrayMember; key=(int*) keyIn; arrayMember=(int*) arrayMemberIn; return (*key) - (*arrayMember); } int intSearchLowEnd(const void* keyIn, const void* arrayMemberIn) { int *key,*arrayMember; key=(int*) keyIn; arrayMember=(int*) arrayMemberIn; // Code here so that bsearch will find ptr to first array // element that has the key. } int intSearchHighEnd(const void* keyIn, const void* arrayMemberIn) { int *key,*arrayMember; key=(int*) keyIn; arrayMember=(int*) arrayMemberIn; // Code here so that bsearch will find ptr to last array // element that has the key. } int mybsearch(int key,int *table,int n) // Elementary binary search for an integer table with n keys { int low,high,mid; low=0; high=n-1; while (1) { mid=(low+high)/2; if (table[mid]==key) return mid; if (table[mid]high) return (-1); } } int mybsearchlastsmaller(int key,int *table,int n) // Finds the highest subscript for an array entry whose // value is smaller than the supplied key { int low,high,mid; low=0; high=n-1; while (1) { mid=(low+high)/2; // put code here } } int mybsearchfirstlarger(int key,int *table,int n) // Finds the lowest subscript for an array entry whose // value is larger than the supplied key { int low,high,mid; low=0; high=n-1; while (1) { mid=(low+high)/2; // put code here } } main() { int i; int *ptr,*lowPtr,*highPtr; int sub,lowSub,highSub; int sum; int numslots,maxkey; // Get table size and range of randomly generated keys scanf("%d %d",&numslots,&maxkey); a=(int*) malloc((numslots+2)*sizeof(int)); if (a==NULL) exit(0); // initialize random number generator srandom(1000); a[0]=(-999); for (i=1;i