#include <stdio.h>
#include <stdlib.h>
typedef struct tree
{
int nVal;
struct tree *pLeft;
struct tree *pRight;
}Tree;
typedef struct queue
{
Tree *nVal;
struct queue *pNext;
}MyQueue;
typedef struct node
{
int nCount;
MyQueue *pHead;
MyQueue *pEnd;
}Queue;
void Init(Queue **pQueue)
{
*pQueue=(Queue *)malloc(sizeof(Queue));
(*pQueue)->nCount=0;
(*pQueue)->pHead=NULL;
(*pQueue)->pEnd=NULL;
}
void Push(Queue **pQueue,Tree * nNum)
{
MyQueue *pNode=(MyQueue*)malloc(sizeof(MyQueue));
pNode->nVal=nNum;
pNode->pNext=NULL;
if((*pQueue)->pHead==NULL)
{
(*pQueue)->pHead=pNode;
}
//尾添加
else
{
(*pQueue)->pEnd->pNext=pNode;
}
(*pQueue)->pEnd=pNode;
(*pQueue)->nCount++;
}
Tree * Pop(Queue *pQueue)
{
Tree * nNum;
MyQueue *pDel=NULL;
//头删除
if(pQueue==NULL || (pQueue)->nCount==0) return NULL;
pDel=(pQueue)->pHead;
nNum=pDel->nVal;
(pQueue)->pHead=(pQueue)->pHead->pNext;
free(pDel);
pDel=NULL;
(pQueue)->nCount--;