-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpre_linear_search.cpp
More file actions
54 lines (42 loc) · 1.12 KB
/
pre_linear_search.cpp
File metadata and controls
54 lines (42 loc) · 1.12 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
53
54
#include <iostream>
#include <array>
#include <vector>
using namespace std;
bool linear_search( vector<int> sequence, int value )
{
// COMPLETE ME
return false;
}
/* this function is designed to test that your function produces the correct results */
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 = {{ {99,true}, {33, true}, {31, false}, {76, false} }};
// populate sequence
int count = 99;
for( int &i : sequence )
{
i = count;
count -= 3;
}
// carry out the tests
for( Test test : testing )
{
bool result = linear_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;
}