function to create a queue of given capacity. It initializes size of queue as 0
| 14 | // of given capacity. |
| 15 | // It initializes size of queue as 0 |
| 16 | struct Queue* createQueue(unsigned capacity) |
| 17 | { |
| 18 | struct Queue* queue = (struct Queue*)malloc( |
| 19 | sizeof(struct Queue)); |
| 20 | queue->capacity = capacity; |
| 21 | queue->front = queue->size = 0; |
| 22 | |
| 23 | // This is important, see the enqueue |
| 24 | queue->rear = capacity - 1; |
| 25 | queue->array = (int*)malloc( |
| 26 | queue->capacity * sizeof(int)); |
| 27 | return queue; |
| 28 | } |
| 29 | |
| 30 | // Queue is full when size becomes |
| 31 | // equal to the capacity |