https://leetcode.com/problems/print-in-order/
코드:
class Foo {
promise<void> one, two;
public:
Foo() {
}
void first(function<void()> printFirst) {
printFirst();
one.set_value();
}
void second(function<void()> printSecond) {
one.get_future().get();
printSecond();
two.set_value();
}
void third(function<void()> printThird) {
two.get_future().get();
printThird();
}
};
|
cs |
풀이 :
class Foo {
promise<void> one, two; // 나중에 실행 시키기로 약속합니다
public:
Foo() {
}
void first(function<void()> printFirst) {
printFirst();
one.set_value(); // 약속을 이행하여 실행 시킵니다
}
void second(function<void()> printSecond) {
one.get_future().get(); // 약속을 실행 시킨 것을 받습니다
printSecond();
two.set_value(); // 나중에 실행 시키기로 약속합니다
}
void third(function<void()> printThird) {
two.get_future().get(); // 약속을 실행 시킨 것을 받습니다
printThird();
}
};
|
cs |
'Leetcode' 카테고리의 다른 글
LeetCode 1115. Print FooBar Alternately [C++/ promise] (0) | 2022.06.03 |
---|---|
LeetCode 1114. Print in Order [C++/ atomic] (0) | 2022.06.03 |
Merge Two Sorted Lists / leetcode / c++ (0) | 2022.06.01 |
Remove Nth Node From End of List, LeetCode, c++/cpp/c (0) | 2022.06.01 |
leetcode Reverse Integer (0) | 2022.05.29 |