MCPcopy Create free account
hub / github.com/algorithm-archivists/algorithm-archive / enqueue

Function enqueue

contents/flood_fill/code/c/flood_fill.c:119–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117}
118
119void enqueue(struct queue *q, struct point element) {
120 if (q->front == (q->back + 1) % q->capacity) {
121 size_t size = sizeof(q->data[0]);
122 struct point *tmp = calloc((q->capacity * 2), size);
123 memcpy(tmp, q->data + q->front, (q->capacity - q->front) * size);
124 memcpy(tmp + q->capacity - q->front, q->data, (q->front - 1) * size);
125
126 free(q->data);
127
128 q->data = tmp;
129 q->back = q->capacity - 1;
130 q->front = 0;
131 q->capacity *= 2;
132 }
133
134 q->data[q->back] = element;
135 q->back = (q->back + 1) % q->capacity;
136}
137
138struct point dequeue(struct queue *q) {
139 struct point ret = q->data[q->front];

Callers 1

queue_fillFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected