MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / findPeakIndex

Function findPeakIndex

CPP/Problems/BitonicArray.cpp:11–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9 using namespace std;
10
11 int findPeakIndex (vector<int> vect, int size) { // find index of peak element
12 int lo = 0, hi = size-1;
13 int mid = lo + (hi - lo)/2;
14
15 while (lo < hi) {
16 if (mid == size-1 || vect[mid] > vect[mid+1]) {
17 hi = mid;
18 }
19 else if (mid == 0 || vect[mid] > vect[mid-1]) {
20 lo = mid+1;
21 }
22 mid = lo + (hi - lo)/2;
23 }
24 return lo;
25 }
26
27 int leftPart (vector<int> vect, int target, int hi) { // search element in left part
28 int lo = 0;

Callers 1

findElementFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected