是否可以进行使用冒泡排序对其进行排序的二进制搜索?
这是我的冒泡排序和二分搜索。我如何将它们结合起来?
int Search_for_Client (int cList[], int low, int high, int target) {
int middle;
while (low <= high) {
middle = low + (high - low)/2;
if (target < cList[middle])
high = middle - 1;
else if (target > cList[middle])
low = middle + 1;
else
return middle;
}
return -1;
}
int bubbleSort(char cList[], int size) {
int swapped;
int p;
for (p = 1; p < size; p++) {
swapped = 0; /* this is to check if the array is already sorted */
int j;
for (j = 0; j < size - p; j++) {
if (cList[j] > cList[j+1]) {
int temp = cList[j];
cList[j] = cList[j+1];
cList[j+1] = temp;
swapped = 1;
}
}
if (!swapped)
{
break; /*if it is sorted then stop*/
}
}
}