#include <iostream>
using namespace std;
const int N = 10;
typedef int ELEMTYPE;
typedef struct Node
{
ELEMTYPE data;
struct Node * next;
}LNode;
typedef struct queue
{
LNode *head;
LNode *tail;
}Queue;
void initQueur(Queue &Q);
int isQueueEmpty(Queue &Q);
int enQueue(Queue &Q, ELEMTYPE e);
int deQueue(Queue &Q, ELEMTYPE &e);
void printQueue(Queue &Q);
int main()
{
Queue Q;
initQueur(Q);
for(int i=1;i<=N;++i)
{
enQueue(Q,i);
}
printQueue(Q);
return 0;
}
void initQueur(Queue &Q)
{
Q.head = new LNode;
Q.head->next = NULL;
Q.tail = Q.head;
}
int isQueueEmpty(Queue &Q)
{
return Q.head == Q.tail;
}
int enQueue(Queue &Q, ELEMTYPE e)
{
LNode *p = new LNode;
p->data = e;
p->next = NULL;
Q.tail->next = p;
Q.tail = p;
return 1;
}
int deQueue(Queue &Q, ELEMTYPE &e)
{
if(isQueueEmpty(Q)) return 0;
LNode *p = Q.head->next;
if(p == Q.tail)
{
Q.tail = Q.head;
}
else
{
Q.head->next = p->next;
}
e = p->data;
delete p;
return 1;
}
void printQueue(Queue &Q)
{
ELEMTYPE e;
while(isQueueEmpty(Q)==0)
{
deQueue(Q,e);
cout<<e<<" ";
}
}