Replace the bubble sort and linear search by shell sort and
Solution
Shell sort
void shellSort(int data[], int len)
{
int m, n, p, temp;
for (m = len / 2; m > 0; m = m / 2)
{
for (n = m; n < len; n++)
{
for(p = n - m; p >= 0; p = p - m)
{
if (data[p+m] >= data[p])
break;
else
{
temp = data[p];
data[p] = data[p+m];
data[p+m] = temp;
}
}
}
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------
void binarySearch(int data[], int len, int val){
int first,last,middle;
first = 0;
last = len - 1;
middle = (first+last)/2;
while (first <= last) {
if (data[middle] < val)
first = middle + 1;
else if (data[middle] == val) {
printf(\"%d found at location %d.\ \", val, middle+1);
break;
}
else
last = middle - 1;
middle = (first + last)/2;
}
if (first > last)
printf(\"Not found\ \", val);
}
![Replace the bubble sort and linear search by shell sort and binary search. The output should be as the following. SolutionShell sort void shellSort(int data[], Replace the bubble sort and linear search by shell sort and binary search. The output should be as the following. SolutionShell sort void shellSort(int data[],](/WebImages/25/replace-the-bubble-sort-and-linear-search-by-shell-sort-and-1064291-1761556453-0.webp)