diff options
Diffstat (limited to 'structures/queue.h')
| -rw-r--r-- | structures/queue.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/structures/queue.h b/structures/queue.h new file mode 100644 index 0000000..368da01 --- /dev/null +++ b/structures/queue.h @@ -0,0 +1,33 @@ +#pragma once + +struct queue +{ + int inf; + queue *next; +}; + +void push(queue *&h, queue *&t, int x) +{ + queue *r = new queue; + r->inf = x; + r->next = NULL; + + if (!h && !t) + h = t = r; + else + { + t->next = r; + t = r; + } +} + +int pop(queue *&h, queue *&t) +{ + queue *r = h; + int i = h->inf; + h = h->next; + + if (!h) t = NULL; + delete r; + return i; +} |