-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbraces.cpp
56 lines (51 loc) · 1.28 KB
/
braces.cpp
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
#include <iostream>
#include <vector>
#include "math.h"
#include "braces.h"
#define DEBUG 0
#if DEBUG == 1
#define LOG(x, y) std::cout << y << " -> " << x << std::endl
#define LOG_V(x, y) std::cout << y << " -> "; \
for(auto i = x.begin(); i != x.end(); i++) { \
std::cout << *i << " "; \
}\
std::cout<<std::endl;
#else
#define LOG(x, y)
#define LOG_V(x, y)
#endif
// Finding the index for the brace to solve
int start_brace(std::vector<double> &v){
int index = -1;// By default we return that there are no braces in the calculation
// We start at the end because if we find '(' we know it OK to use it with no fear of anther braces in it
for (int i = v.size()-1;i >= 0; i--) {
if (v[i] == OPERATION.at('(')) {
index = i;
break;
}
}
return index;
}
// The start and the finish index
std::vector<int> start_and_finish_ind(std::vector<double> &v){
// The indexes
std::vector<int> indexes;
// Place of brace
int index = start_brace(v);
if (index == -1) {
// Empty vector tell there is no braces
LOG("[]", "Braces range");
return indexes;
}
indexes.push_back(index);
int end = v.size() - 1;
for(size_t i = index;i<v.size();i++){
if (v[i] == OPERATION.at(')')) {
end = i;
break;
}
}
indexes.push_back(end);
LOG_V(indexes, "Braces range");
return indexes;
}