Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void queue_insert(queue *q, data v) {
- q->rear = (q->rear + 1) % q->capacity;
- if (q->size == q->rear) {
- q->capacity <<= 1; // double the capacity of the circular queue
- q->values = realloc(q->values, sizeof(data) * q->capacity);
- }
- q->values[q->rear] = v;
- q->size++;
- return;
- }
- the queue is a circular queue. Here is the structure:
- typedef struct {
- unsigned int capacity; ///< current capacity of the queue.
- int front; ///< index of front element of the queue.
- int rear; ///< index of next rear element of the queue.
- int size; ///< count of number of values in the queue.
- data *values; ///< array of data values.
- } queue;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement