-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlab_binary_search_recursive.cpp
More file actions
52 lines (41 loc) · 1.06 KB
/
lab_binary_search_recursive.cpp
File metadata and controls
52 lines (41 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <array>
#include <vector>
using namespace std;
bool binary_search( vector<int> sequence, int value, int start=-1, int end=-1 )
{
// COMPLETE ME
return false;
}
int main()
{
int errflg = 0;
const int size = 33;
vector<int> sequence;
sequence.resize(size);
// search test values and results
struct Test
{
int value;
bool expected;
};
array<Test,4> testing = {{ {96,true}, {33, true}, {31, false}, {76, false} }};
// populate sequence
int count = 0;
for( int &i : sequence )
{
i = count;
count += 3;
}
// carry out the tests
for( Test test : testing )
{
bool result = binary_search( sequence, test.value );
cout << (result == test.expected ? "Passed" : "Failed") <<
" search for " << test.value << " test, got " <<
(result ? "true" : "false") << " expected " <<
(test.expected ? "true" : "false") << endl;
if( result != test.expected ) errflg += 1;
}
return errflg;
}