#include <stdio.h>
#include <stdlib.h>#define maxsize 5
typedef struct LinkNode {int data;struct LinkNode *next;
} LinkNode;typedef struct {LinkNode *front, *rear;//链表头,链表尾
} LinkQueue;void initQueue(LinkQueue &q) {q.front = q.rear = (LinkNode *) malloc(sizeof(LinkNode));q.front->next = NULL;
}bool isEmpty(LinkQueue q) {if (q.rear == q.front) { return true; } else { return false; }
}bool enQueue(LinkQueue &q, int num) {LinkNode *p = (LinkNode *) malloc(sizeof(LinkNode));p->data = num;p->next = NULL;q.rear->next = p;//尾指针的next指向p,从尾部入队q.rear = p;//rear指向新的尾部return true;
}bool deleteQueue(LinkQueue &q, int &e) {if (q.front == q.rear) {return false;} else {}LinkNode *pc = q.front->next;//拿到被删节点q.front->next = pc->next;e = pc->data;free(pc);if (q.rear == pc) {q.rear = q.front;}return true;
}int main() {LinkQueue q;initQueue(q);isEmpty(q);bool result;enQueue(q, 1);enQueue(q, 2);enQueue(q, 3);enQueue(q, 4);enQueue(q, 5);int e;result = deleteQueue(q, e);if (result) {printf("success\n");} else {printf("fail\n");}
}