C++ Simplest Solution Using Semaphores
\n#include <semaphore.h>\n\nclass ZeroEvenOdd {\nprivate:\n    int n;\n    sem_t zero_sem;\n    sem_t even_sem;\n    sem_t odd_sem;\n    \npublic:\n    ZeroEven
```\n#include <semaphore.h>\n\nclass ZeroEvenOdd {\nprivate:\n    int n;\n    sem_t zero_sem;\n    sem_t even_sem;\n    sem_t odd_sem;\n    \npublic:\n    ZeroEvenOdd(int n) {\n        this->n = n;\n        sem_init(&zero_sem, 0, 1);\n        sem_init(&even_sem, 0, 0);\n        sem_init(&odd_sem, 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(&zero_sem);\n            printNumber(0);\n            if (i % 2 == 0)\n                sem_post(&even_sem);\n            else\n                sem_post(&odd_sem);\n        }\n        \n    }\n\n    void even(function<void(int)> printNumber) {\n        for (int i = 2; i <= n; i += 2) {\n            sem_wait(&even_sem);\n            printNumber(i);\n            sem_post(&zero_sem);\n        }\n    }\n\n    void odd(function<void(int)> printNumber) {\n        for (int i = 1; i <= n; i += 2) {\n            sem_wait(&odd_sem);\n            printNumber(i);\n            sem_post(&zero_sem);\n        }\n    }\n};\n```\n**Like it? please upvote...**
[]