Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write it in C ET 2100 Quiz 14 Fall 2015 Name Meh Write the E111 Random,linearsea

ID: 3692405 • Letter: W

Question


Write it in C
ET 2100 Quiz 14 Fall 2015 Name Meh Write the E111 Random,linearsearch, and binarysearch functions in the stand code fragment illustrates how they are used s in the standard way. The folowing const int SIZE = 1234567; int alSIZE) fillRandom (a, SIZE, 100, 200) int loc444LS linearSearch (a,. SIZE, 444), sort (a, SIZE) int loc444BS = bina rySearch (a, STZE, 444); /s1z0 of the array / declaze the array 11with candom integers /* get index of ele don't vorzy about thi /.gee index of ele 1. (8) Finish this function. it fills the array with integers from rst to last, both ends included fil1Random (int x).int size, int first, int last) i void

Explanation / Answer

void fillRandom (int x[], int SIZE, int first, int last)
{
int i;
for (i = 0; i < SIZE; ++i)
{
x[i] = ( rand() % first ) + last;
}

}

void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}

// A function to implement bubble sort
void sort(int A[], int SIZE)
{

int i, j;
for (i = 0; i < SIZE-1; i++)   
{
for (j = 0; j < SIZE-i-1; j++)

{
printf("kakajaj ");
if (A[j] > A[j+1])
swap(&A[j], &A[j+1]);
}
}
}


// Invariant: A[l] <= key and A[r] > key
// Boundary: |r - l| = 1
// Input: A[l .... r-1]
int binarySearch(int A[], int SIZE, int key)
{
int m;
int l = 0;
int r = SIZE -1;
while( r - l > 1 )
{
m = l + (r-l)/2;

if( A[m] <= key )
l = m;
else
r = m;
}

if( A[l] == key )
return l;
else
return -1;
}

int linearSearch(int A[], int SIZE, int key)
{
int i;
for (i = 0; i < SIZE; ++i)
{
if(A[i] == key) return i;
}

return -1;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote