nihonium
/
mipt_clang
Archived
1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

37 lines
622 B
C

3 years ago
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
typedef int T;
typedef struct queue_s {
T *body, *begin, *end, *body_end;
} queue;
queue* queue_new(size_t size) {
queue *t = (queue *)malloc(sizeof(queue));
assert(t != NULL);
t->body = (int *)malloc(sizeof(T)*size);
t->begin = t->end = t->body;
t->body_end = t->body + size;
return t;
}
void queue_delete(queue *t) {
free(t->body);
free(t);
}
void queue_enqueue(queue *t, T el) {
assert(t->end < t->body_end);
*t->end++ = el;
}
int queue_empty(queue const *t) {
return t->begin == t->end;
}
T queue_dequeue(queue *t) {
return *t->begin++;
}