C Solution using 3 semaphores
\ntypedef struct \n{\n    int n;\n    sem_t zero_;\n    sem_t even_;\n    sem_t odd_;\n\n} ZeroEvenOdd;\n\nZeroEvenOdd* zeroEvenOddCreate(int n) \n{\n    ZeroEv
```\ntypedef struct \n{\n    int n;\n    sem_t zero_;\n    sem_t even_;\n    sem_t odd_;\n\n} ZeroEvenOdd;\n\nZeroEvenOdd* zeroEvenOddCreate(int n) \n{\n    ZeroEvenOdd* obj = (ZeroEvenOdd*) malloc(sizeof(ZeroEvenOdd));\n    obj->n = n;\n    \n    //initialize semaphores\n    sem_init(&obj->zero_, 0, 1);\n    sem_init(&obj->even_, 0, 0);\n    sem_init(&obj->odd_, 0, 0);\n    \n    return obj;\n}\n\n// You may call global function `void printNumber(int x)`\n// to output "x", where x is an integer.\n\nvoid zero(ZeroEvenOdd* obj) \n{\n    for(int i = 1; i <= obj->n; i++)\n    {    \n        sem_wait(&obj->zero_);\n        \n        printNumber(0);\n    \n        if(i % 2 == 0)\n            sem_post(&obj->even_);\n        else\n            sem_post(&obj->odd_);\n    }\n}\n\nvoid even(ZeroEvenOdd* obj) \n{\n    for(int i = 2; i <= obj->n; i+=2)\n    {    \n        sem_wait(&obj->even_);\n        \n        printNumber(i);\n    \n        sem_post(&obj->zero_);\n    }\n   \n}\n\nvoid odd(ZeroEvenOdd* obj) \n{\n    ;\n    for(int i = 1; i <= obj->n; i+=2)\n    {    \n        sem_wait(&obj->odd_);\n        \n        printNumber(i);\n    \n        sem_post(&obj->zero_);\n    }\n\n   \n}\n\nvoid zeroEvenOddFree(ZeroEvenOdd* obj) \n{\n    sem_destroy(&obj->zero_);\n    sem_destroy(&obj->even_);\n    sem_destroy(&obj->odd_);\n    \n    free(obj);\n    obj = NULL;\n}\n```
[]