Skip to content

Commit ba48fc1

Browse files
authored
chore(formatting): apply code formatting for searches ternary search i
1 parent 3091a73 commit ba48fc1

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
double ternary_search(const function<double(double)> &func, double low, double high) {
1+
double ternary_search(const function<double(double)> &func, double low,
2+
double high) {
23
int it = 0;
34
while (it < 100) { // with 50 iterations it has precision for 1e-9
45
double diff = (high - low) / 3.0;
5-
double mid1 = low + diff;
6-
double mid2 = high - diff;
6+
double mid1 = low + diff, mid2 = high - diff;
77

8-
double f1 = func(mid1);
9-
double f2 = func(mid2);
8+
double f1 = func(mid1), f2 = func(mid2);
109

1110
if (f1 > f2) // change to < to find the maximum
1211
low = mid1;
@@ -17,4 +16,4 @@ double ternary_search(const function<double(double)> &func, double low, double h
1716
return func(low);
1817
}
1918
// Usage:
20-
// double ans = ternary_search(funct1, low, high);
19+
// double ans = ternary_search(funct1, low, high);

0 commit comments

Comments
 (0)