Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void queue_init(queue *q)
- {
- q->head = 0;
- q->tail = -1;
- q->count = 0;
- }
- void enqueue(queue *q, queue_item x)
- {
- if (!queue_full(*q))
- {
- q->tail = (q->tail + 1) % QUEUE_MAX_SIZE;
- q->items[q->tail] = x;
- q->count++;
- }
- }
- queue_item dequeue(queue *q)
- {
- if (!queue_empty(*q))
- {
- queue_item x = q->items[q->head];
- q->head = (q->head + 1) % QUEUE_MAX_SIZE;
- q->count--;
- return x;
- }
- }
- queue_item queue_top(queue q)
- {
- return q.items[q.head];
- }
- int queue_full(queue q)
- {
- return (q.count == QUEUE_MAX_SIZE);
- }
- int queue_empty(queue q)
- {
- return (q.count == 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement