Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <stdio.h>
- #include <locale.h>
- #include <windows.h>
- const UCHAR N = 3, Q_EMPTY = 2, Q_FULL = 1;
- struct queue
- {
- UCHAR begin = 0, end = 0;
- LONGLONG data[N] = { 0 };
- };
- UCHAR push(queue &q, LONGLONG elem);
- UCHAR pop(queue &q, LONGLONG &elem);
- bool is_empty(queue q);
- bool is_full(queue q);
- void clear(queue &q);
- void print(queue q);
- int main()
- {
- queue Q;
- return 0 * _getch();
- }
- UCHAR push(queue &q, LONGLONG elem)
- {
- bool is_f = is_pfull(q);
- if (!is_f)
- {
- q.end++;
- q.data[q.end] = elem;
- }
- return is_f ? Q_FULL : 0;
- }
- UCHAR pop(queue &q, LONGLONG &elem)
- {
- bool is_e = is_empty(q);
- if (!is_e)
- {
- elem = q.data[q.begin];
- q.data[q.begin] = 0;
- q.begin++;
- }
- return is_e ? Q_EMPTY : 0;
- }
- bool is_empty(queue q)
- {
- return q.end == q.begin;
- }
- bool is_full(queue q)
- {
- return q.end == N -1 && q.begin == 0;
- }
- bool is_pfull(queue q)
- {
- return q.end == N - 1 && q.begin;
- }
- void clear(queue &q)
- {
- for (LONGLONG n = 0; !is_empty(q); pop(q, n));
- }
- void print(queue q)
- {
- LONGLONG n = 0;
- while (!is_empty(q))
- {
- pop(q, n);
- printf_s("%lld", n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement