首页 » 编程之美 » 正文

[leetcode]Print in Order

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

    void first(function<void()> printFirst) {
        while (!isThird);
        isThird = false;
        isSecond = false;
        printFirst();        
        // printFirst() outputs "first". Do not change or remove this line.
        isFirst = true;
    }

    void second(function<void()> printSecond) {
        while(!isFirst);
        isFirst = false;
        isThird = false;
        // printSecond() outputs "second". Do not change or remove this line.
        printSecond();
        isSecond = true;
    }

    void third(function<void()> printThird) {
        while(!isSecond);
        isFirst = false;
        isSecond = false;
        // printThird() outputs "third". Do not change or remove this line.
        printThird();
        isThird = true;
    }
};

发表评论

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax