typedef struct Node{
int data;
struct Node *next;
}Node;
typedef struct {
Node *front;//队首指针
Node *rear;//队尾指针
}Queue;
Queue * EnQueue(Queue *queue,int e)
{//向队尾插入一个结点
Node *newptr;//指向新结点的指针
newptr=malloc(sizeof(Node));
if(newptr!=NULL)
{
newptr->data=e;
newptr->next=NULL;
if(queue==NULL)
{
queue=malloc(sizeof(Queue));
queue->front=newptr;
queue->rear=newptr;
}
else
{
queue->rear->next=newptr;
queue->rear=newptr;
}
}
else{
printf("can not insert ,no memory available./n");
}
return queue;
}
Queue * DeQueue(Queue *s,int * e)
{//删除队首元素
Node *temp;
temp=s->front;
*e=temp->data;//将队首的值存入e中
s->front=s->front->next;
free(temp);
if(s->front==NULL)
s=NULL;
return s;
}
void printQueue(Queue *s)
{
if(s==NULL)
printf("the queue is empty./n");
else
{
Node *p;
p=s->front;
printf("the queue is:");
while(p!=NULL)
{
printf("%d-->",p->data);
p=p->next;
}
printf("/n");
}
}