操作二叉树使用的队列

/*BiTree_Queue.h  操作二叉树使用的队列*/


//构造一个空队列
Status InitQueue(LinkQueue &L)
{
    L.rear=L.front=(QueueLink)malloc(sizeof(QNode));
    if(!L.rear)exit(-1);
    L.front->next=NULL;
    return TRUE;
}

//销毁队列
Status DestroyQueue(LinkQueue &L)
{
    while(L.front)
    {
        L.rear=L.front->next;
        L.front=L.rear->next;
        free(L.rear);
    //    L.front=L.rear;
    }
    return TRUE;
}

//清空队列
Status ClearQueue(LinkQueue &L)
{
    QueueLink q,p=L.front->next;

    while(p)
    {
        q=p;
        p=p->next;
        free(q);
    }
    L.rear=L.front;
    return TRUE;
}

//进队列
Status EnQueue(LinkQueue &L,ElemType e)
{
    QueueLink p;
    p=(QueueLink)malloc(sizeof(QNode));
    if(!p)exit(-1);
    p->data=e;
    p->next=NULL;
    L.rear->next=p;
    L.rear=p;
    return TRUE;
}

//出队列
Status DeQueue(LinkQueue &L,ElemType &e)
{
    if(L.front==L.rear)return FALSE;
    QueueLink p=L.front->next;
    e=p->data;
    L.front->next=p->next;   
    if(L.rear==p)L.rear=L.front;
    free(p);
    return TRUE;   
}

//判断队列是否为空
Status QueueEmpty(LinkQueue L)
{
    if(L.rear==L.front)
        return TRUE;
    return FALSE;
}

//得到ElemType &e队首元素
Status GetHead(LinkQueue L,ElemType &e)
{
    if(QueueEmpty(L))return FALSE;
    e=L.front->next->data;
    return TRUE;
}
//返回队列长度
int QueueLength(LinkQueue L)
{
    int i=0;
    QueueLink p=L.front->next;
    while(p!=NULL)
    {
        p=p->next;
        i++;
    }
    return i;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值