29 lines
589 B
C
29 lines
589 B
C
|
int binary_search(int arr[], int m, int size) {
|
||
|
int low = 0;
|
||
|
int high = size - 1;
|
||
|
while (low != high) {
|
||
|
int mid = (low + high) / 2;
|
||
|
if (m == arr[mid]) {
|
||
|
return mid;
|
||
|
} else if (m > arr[mid]) {
|
||
|
low = mid + 1;
|
||
|
} else {
|
||
|
high = mid - 1;
|
||
|
};
|
||
|
}
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
void bubble_sort(int a[], int n) {
|
||
|
int i = 0, j = 0, tmp;
|
||
|
for (i = 0; i < n; i++) {
|
||
|
for (j = 0; j < n - i - 1; j++) {
|
||
|
if (a[j] > a[j+1]) {
|
||
|
tmp = a[j];
|
||
|
a[j] = a[j+1];
|
||
|
a[j + 1] = tmp;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|