Skip to content

Commit 4926e50

Browse files
authored
chore(formatting): apply code formatting for searches ternary search ii
1 parent ba48fc1 commit 4926e50

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,13 +1,12 @@
11
// This version is slower than the iterations version.
2-
double ternary_search(const function<double(double)> &func, double low, double high) {
2+
double ternary_search(const function<double(double)> &func, double low,
3+
double high) {
34
double eps = 1e-9;
45
while (high - low > eps) {
56
double diff = (high - low) / 3.0;
6-
double mid1 = low + diff;
7-
double mid2 = high - diff;
7+
double mid1 = low + diff, mid2 = high - diff;
88

9-
double f1 = func(mid1);
10-
double f2 = func(mid2);
9+
double f1 = func(mid1), f2 = func(mid2);
1110

1211
if (f1 > f2) // change to < to find the maximum
1312
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)