首页 » 编程之美 » 正文

[leetcode]Print in Order

class Foo {
private:
    bool isFirst;
    bool isSecond;
    bool isThird;
public:
    Foo() {
        isFirst = false;
        isSecond = false;
        isThird = true;
    }</p>

<pre><code>void first(function&amp;lt;void()&amp;gt; printFirst) {
    while (!isThird);
    isThird = false;
    isSecond = false;
    printFirst();        
    // printFirst() outputs &amp;quot;first&amp;quot;. Do not change or remove this line.
    isFirst = true;
}

void second(function&amp;lt;void()&amp;gt; printSecond) {
    while(!isFirst);
    isFirst = false;
    isThird = false;
    // printSecond() outputs &amp;quot;second&amp;quot;. Do not change or remove this line.
    printSecond();
    isSecond = true;
}

void third(function&amp;lt;void()&amp;gt; printThird) {
    while(!isSecond);
    isFirst = false;
    isSecond = false;
    // printThird() outputs &amp;quot;third&amp;quot;. Do not change or remove this line.
    printThird();
    isThird = true;
}
</code></pre>

<p>};

发表评论