-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.h
50 lines (39 loc) · 826 Bytes
/
tasks.h
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
//
// Created by SP on 2022/7/12.
//
#ifndef TASKS_H
#define TASKS_H
struct node {
void (*f)();
node *last;
node *next;
};
class TASKS {
private:
node left = {[]() {}, nullptr, nullptr};
node right = {[]() {}, nullptr, nullptr};
public:
TASKS();
void add(void (*f)());
void run();
};
TASKS::TASKS() {
this->left.next = &this->right;
this->right.last = &this->left;
}
void TASKS::add(void (*f)()) {
node *cur = new node();
cur->f = f;
this->right.last->next = cur;
cur->last = this->right.last;
cur->next = &this->right;
this->right.last = cur;
}
void TASKS::run() {
node *cur = this->left.next;
while (cur != &this->right) {
cur->f();
cur = cur->next;
}
}
#endif //TASKS_H