typedef int element;
typedef struct QueueNode {
element data;
struct QueueNode* link;
} QueueNode;
typedef struct {
QueueNode* front, * rear;
}LinkedQueueType;
int is_empty(LinkedQueueType *q) {
if (q->front = q->rear) {
return 1;
}
else {
return 0;
}
}
int is_full(LinkedQueueType *q) {
q->rear = q->rear + 1 % MAX_QUEUE_SIZE;
if (q->rear = q->front) {
return 1;
}
else {
return 0;
}
}
void enqueue(LinkedQueueType* q, element data) {
QueueNode* temp = (QueueNode*)malloc(sizeof(QueueNode));
temp->data = data;
temp->link = NULL;
if (is_empty(q)) {
q->front = temp;
q->rear = temp;
}
else {
q->rear->link = temp;
q->rear = temp;
}
}
element dequeue(LinkedQueueType* q) {
if (is_empty(q)) {
printf(stderr, "스택이 비어있음\n");
exit(1);
}
else {
q->front = q->front + 1 % MAX_QUEUE_SIZE;
return q->front;
}
}
int main() {
LinkedQueueType* q;
init(q);
enqueue(q, 1);
enqueue(q, 2);
enqueue(q, 3);
enqueue(q, 4);
dequeue(q);
enqueue(q, 5);
enqueue(q, 6);
dequeue(q);
dequeue(q);
queue_print(q);
return 0;
}