Skip to content

Commit 2a55493

Browse files
committed
Format C code using CLANG_FORMAT
1 parent b5c0e1f commit 2a55493

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2589
-2584
lines changed

src/c/BinarySearch.c

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
#include<stdio.h>
1+
#include <stdio.h>
22

33
int BinarySearch(int array[], int size, int value) {
4-
int start = 0;
5-
int end = size - 1;
6-
int middle = end / 2;
4+
int start = 0;
5+
int end = size - 1;
6+
int middle = end / 2;
77

8-
while (start < end && array[middle] != value) {
9-
// new start
10-
if (value > array[middle])
11-
start = middle + 1;
8+
while (start < end && array[middle] != value) {
9+
// new start
10+
if (value > array[middle])
11+
start = middle + 1;
1212

13-
// new end
14-
if (value < array[middle])
15-
end = middle - 1;
13+
// new end
14+
if (value < array[middle])
15+
end = middle - 1;
1616

17-
// new middle
18-
middle = (start + end) / 2;
19-
}
17+
// new middle
18+
middle = (start + end) / 2;
19+
}
2020

21-
if (array[middle] == value)
22-
return middle;
21+
if (array[middle] == value)
22+
return middle;
2323

24-
return -1;
24+
return -1;
2525
}
2626

2727
int main() {
28-
int value;
29-
int array[] = {1, 5, 10, 12, 18, 22, 87, 90, 112, 129};
30-
size_t size = sizeof(array) / sizeof(array[0]);
28+
int value;
29+
int array[] = {1, 5, 10, 12, 18, 22, 87, 90, 112, 129};
30+
size_t size = sizeof(array) / sizeof(array[0]);
3131

32-
printf("Please provide the number you want to value for: ");
33-
scanf("%d", &value);
32+
printf("Please provide the number you want to value for: ");
33+
scanf("%d", &value);
3434

35-
int pos = BinarySearch(array, size, value);
35+
int pos = BinarySearch(array, size, value);
3636

37-
if (pos != -1)
38-
printf("Found in position = %d.\nValue = %d\n", pos, array[pos]);
39-
else
40-
printf("Not found\n");
37+
if (pos != -1)
38+
printf("Found in position = %d.\nValue = %d\n", pos, array[pos]);
39+
else
40+
printf("Not found\n");
4141

42-
return 0;
42+
return 0;
4343
}

0 commit comments

Comments
 (0)