-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinarySearch.cpp
More file actions
59 lines (50 loc) · 1.39 KB
/
binarySearch.cpp
File metadata and controls
59 lines (50 loc) · 1.39 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
55
56
57
58
59
#include <iostream>
#include <string>
#include <vector>
bool binarySearch(std::vector<std::string> lines, std::string input){
bool blankTiles = false;
unsigned int vMid = lines.size() / 2;
unsigned int vMin = 0;
unsigned int vMax = lines.size() - 1;
unsigned int stringI = 0;
while (vMin < vMax && stringI < input.length()){
vMid = (vMin + vMax) / 2;
if (input.at(stringI) == '?'){ //Check to see if a blank tile is in play. This will change how the final evaluation is done.
blankTiles = true;
stringI++;
continue;
}
else if (lines.operator[](vMid).at(stringI) == input.at(stringI)){
int vMinTemp = vMid;
int vMaxTemp = vMid;
while (vMinTemp != 0 &&lines.operator[](vMinTemp).at(stringI) == lines.operator[](vMinTemp - 1).at(stringI)){
vMinTemp--;
}
while (vMaxTemp != lines.size() - 1 && lines.operator[](vMaxTemp).at(stringI) == lines.operator[](vMaxTemp + 1).at(stringI)){
vMaxTemp++;
}
vMin = vMinTemp;
vMax = vMaxTemp;
stringI++;
continue;
}
else if (lines.operator[](vMid).at(stringI) < input.at(stringI)){
vMin = vMid + 1;
}
else {
vMax = vMid - 1;
}
}
if (blankTiles == false){
if (input.compare(lines.operator[](vMin)) == 0){
return(true);
}
else {
return (false);
}
}
else {
//Do a thing... I don't know what yet. Just return true for now.
return(true);
}
}