#include <stdio.h>
#include<stdlib.h>
struct QNode {
int n;
struct QNode* next;
};
struct QNode* initQueue() {
struct QNode* p = (struct QNode*)malloc(sizeof(struct QNode));
p->next = NULL;
return p;
}
struct QNode* inNode(struct QNode* rear, int a) {
struct QNode* p = (struct QNode*)malloc(sizeof(struct QNode));
p->n = a;
p->next = NULL;
rear->next = p;
rear = p;
printf("%d\t成功入栈\n", p->n);
return rear;
}
void outNode(struct QNode* head) {
if (head->next == NULL) {
exit(0);
}
struct QNode* p = (struct QNode*)malloc(sizeof(struct QNode));
p = head->next;
printf("%d\t出栈成功\n", p->n);
head->next = p->next;
free(p);
}
int main() {
struct QNode* head, * rear;
head=rear = initQueue();
rear = inNode(rear, 1);
rear = inNode(rear, 3);
rear = inNode(rear, 5);
rear = inNode(rear, 9);
outNode(head);
outNode(head);
outNode(head);
outNode(head);
return 0;
}