Condition Variable
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass ZeroEvenOdd {\nprivate:\n    int n;\n    mutex mtx;\n    condition_variable cv;\n    int state;\n    int parity;\n\npublic:\n    ZeroEvenOdd(int n) {\n        this->n = n;\n        state = 0;\n        parity = 1;\n    }\n\n    // printNumber(x) outputs "x", where x is an integer.\n    void zero(function<void(int)> printNumber) {\n        for (int i=0;i<n;++i){\n            unique_lock<mutex> lck(mtx);\n            cv.wait(lck, [this](){return state == 0;});\n            state = 1;\n            printNumber(0);\n            cv.notify_all();\n        }\n    }\n\n    void even(function<void(int)> printNumber) {\n        for (int i=2;i<=n;i+=2){\n            unique_lock<mutex> lck(mtx);\n            cv.wait(lck, [this](){return state == 1 && parity == 0;});\n            state = 0;\n            parity = 1;\n            printNumber(i);\n            cv.notify_all();\n        }\n    }\n\n    void odd(function<void(int)> printNumber) {\n        for (int i=1;i<=n;i+=2) {\n            unique_lock<mutex> lck(mtx);\n            cv.wait(lck, [this](){return state == 1 && parity == 1;});\n            state = 0;\n            parity = 0;\n            printNumber(i);\n            cv.notify_all();\n        }\n    }\n};\n```
['C++']