C++ Simple 3 Semaphore, easy to understand
c++\npublic:\n    ZeroEvenOdd(int n) {\n        this->n = n;\n        sem_init(&sem_z, 0 ,1);\n        sem_init(&sem_o, 0 ,0);\n        sem_init(&sem_e, 0 ,0);\
```c++\npublic:\n    ZeroEvenOdd(int n) {\n        this->n = n;\n        sem_init(&sem_z, 0 ,1);\n        sem_init(&sem_o, 0 ,0);\n        sem_init(&sem_e, 0 ,0);\n    }\n\n    // printNumber(x) outputs "x", where x is an integer.\n    void zero(function<void(int)> printNumber) {\n        for (int i = 1; i <= n; i++) {\n            sem_wait(&sem_z);\n            printNumber(0);\n            if (i%2 == 0)\n                sem_post(&sem_e);\n            else\n                sem_post(&sem_o);\n        }\n    }\n\n    void even(function<void(int)> printNumber) {\n        for (int i = 2; i <= n; i+= 2) {\n            sem_wait(&sem_e);\n            printNumber(i);\n            sem_post(&sem_z);\n        }\n    }\n\n    void odd(function<void(int)> printNumber) {\n        for (int i = 1; i <= n; i+= 2) {\n            sem_wait(&sem_o);\n            printNumber(i);\n            sem_post(&sem_z);\n        }\n    }\n};\n```
['C', 'C++']