Commit 8e5a5a6e authored by Michael's avatar Michael

michael.davityan:exercise_07_33v3

parent 427eff9e
progname=exercise_07_33
CC=g++
CFLAGS=-Wall -Wextra -Werror -g3
CFLAGS=-g3
all: test1 test2
all: test1 test2
debug/$(progname): debug/$(progname).o
$(CC) $(CFLAGS) $< -o $@
......@@ -23,7 +23,7 @@ clean:
rm -r debug Tests/*.out
test%: debug/$(progname)
@./debug/$(progname) < Tests/$@.in > Tests/$@.out 2>&1 || echo "$@ is executing..."
@./debug/$(progname) test < Tests/$@.in > Tests/$@.out 2>&1 || echo "$@ is executing..."
@diff Tests/$@.out Tests/$@.expected && echo PASSED || echo FAILED
.PRECIOUS: debug/%.ii debug/%.s
......
Found value in element 12
element value
1 184
2 87
3 178
4 116
5 194
6 136
7 187
8 93
9 50
10 22
11 163
12 28
13 91
14 60
15 164
16 127
17 141
18 27
19 173
20 137
21 12
22 169
23 168
24 30
25 183
26 131
27 63
28 124
29 68
30 136
31 130
32 3
33 23
34 59
35 70
36 168
37 194
38 57
39 12
40 43
41 30
42 174
43 22
44 120
45 185
46 138
47 199
48 125
49 116
50 171
51 14
52 127
53 92
54 181
55 157
56 74
57 63
58 171
59 197
60 82
61 106
62 126
63 85
64 128
65 137
66 106
67 47
68 130
69 114
70 58
71 125
72 96
73 183
74 146
75 15
76 168
77 35
78 165
79 44
80 151
81 88
82 9
83 77
84 179
85 189
86 185
87 4
88 52
89 155
90 200
91 133
92 61
93 77
94 169
95 140
96 13
97 27
98 187
99 95
100 140
Found value in element 83
element value
1 184
2 87
3 178
4 116
5 194
6 136
7 187
8 93
9 50
10 22
11 163
12 28
13 91
14 60
15 164
16 127
17 141
18 27
19 173
20 137
21 12
22 169
23 168
24 30
25 183
26 131
27 63
28 124
29 68
30 136
31 130
32 3
33 23
34 59
35 70
36 168
37 194
38 57
39 12
40 43
41 30
42 174
43 22
44 120
45 185
46 138
47 199
48 125
49 116
50 171
51 14
52 127
53 92
54 181
55 157
56 74
57 63
58 171
59 197
60 82
61 106
62 126
63 85
64 128
65 137
66 106
67 47
68 130
69 114
70 58
71 125
72 96
73 183
74 146
75 15
76 168
77 35
78 165
79 44
80 151
81 88
82 9
83 77
84 179
85 189
86 185
87 4
88 52
89 155
90 200
91 133
92 61
93 77
94 169
95 140
96 13
97 27
98 187
99 95
100 140
Value not found
#include <iostream>
#include <iomanip>
#include <unistd.h>
#include <cstdlib>
#include <ctime>
int
recursiveLinearSearch(const int integersArray[], const size_t sizeOfArray, const int searchKey,
......@@ -11,29 +14,33 @@ recursiveLinearSearch(const int integersArray[], const size_t sizeOfArray, const
if (firstIdx == sizeOfArray) {
return -1;
}
return recursiveLinearSearch(integersArray, searchKey, sizeOfArray, firstIdx + 1);
return recursiveLinearSearch(integersArray, sizeOfArray, searchKey, firstIdx + 1);
}
int
main(int argc, char **argv)
{
if (1 == argc) {
std::srand(std::time(0));
}
const size_t ARRAY_SIZE = 100;
int integersArray[ARRAY_SIZE] ;
std::cout << "element\t" << std::setw(8) << "value" << std::endl;
for (size_t index = 0; index < ARRAY_SIZE; ++index) {
integersArray[index] = 2 * index;
integersArray[index] = 1 + rand() % 200;
std::cout << index + 1 << "\t" << std::setw(6) << integersArray[index] << std::endl;
}
if (::isatty(STDIN_FILENO)) {
std::cout << "Enter integer search key: ";
}
int searchKey;
std::cin >> searchKey;
const int elementIdx = recursiveLinearSearch(integersArray, searchKey, ARRAY_SIZE) ;
const int elementIdx = recursiveLinearSearch(integersArray, ARRAY_SIZE, searchKey);
if (elementIdx != -1) {
std::cout << "Found value in elementIdx " << elementIdx << "\n";
std::cout << "Found value in element " << elementIdx + 1 << "\n";
} else {
std::cout << "Value not found" << std::endl;
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment