#include<iostream>
#include<stack>
#include<cmath>
#define MAXSIZE 30
using namespace std;
typedef struct Node {
int data;
Node* next;
}LinkQueueNode;
typedef struct LinkNode{
LinkQueueNode* front;
LinkQueueNode* rear;
}*LinkQueue;
void initQueue(LinkQueue* q) {
*q = (LinkNode*)malloc(sizeof(LinkNode));
Node* p = (Node*)malloc(sizeof(Node));
p->data = 0;
p->next = NULL;
(*q)->front = p;
(*q)->rear = p;
}
bool EnterQueue(LinkQueue q, int n) {
Node* p = (Node*)malloc(sizeof(Node));
if (p == NULL)
return false;
p->data = n;
q->rear->next = p;
q->rear = p;
p->next = NULL;
return true;
}
bool DeleteQueue(LinkQueue q, int* n) {
if (q->front->next == NULL)
return false;
Node* p = q->front->next;
q->front->next = p->next;
*n = p->data;
free(p);
return true;
}
void coutQueue(LinkQueue q) {
Node* p = q->front;
cout << "Queue: ";
while (p->next != NULL) {
p = p->next;
cout << p->data << " ";
}
cout << endl;
}
int main() {
LinkQueue q;
initQueue(&q);
for (int i = 0; i < 11; i++) {
EnterQueue(q, i);
}
coutQueue(q);
for (int i = 0; i < 5; i++) {
int n = 0;
DeleteQueue(q, &n);
cout << "Delete: " << n;
}
cout << endl;
coutQueue(q);
return 0;
}