-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmultiplefunction.cpp
52 lines (43 loc) · 1.04 KB
/
multiplefunction.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
#include "header.h"
using namespace std;
class MinStack {
public:
/** initialize your data structure here. */
stack<pair<int,int>> stk;
stack<pair<int,int>> minStk;
int id;
MinStack() {
id = 0;
}
void push(int x) {
stk.push({id, x});
if(minStk.empty() || x<=minStk.top().second){
minStk.push({id, x});
}
id++;
}
void pop() {
auto [tid, tx] = stk.top();
stk.pop();
if(!minStk.empty() && tid==minStk.top().first){
minStk.pop();
}
}
int top() {
return stk.top().second;
}
int min() {
return minStk.top().second;
}
};
#define REGISTER(func) exc.registerMemberFunction(#func, &MinStack::func);
int main() {
// Excecutor的第一个模板参数为类名,第二个模板参数为false;
Excecutor<MinStack, false> exc("../multiplefunction.txt");
exc.instance = exc.createInstance<void>();
REGISTER(push)
REGISTER(pop)
REGISTER(top)
REGISTER(min)
exc.run();
}