首页 > 其他 > 详细

队列的链式存储---链表实现

时间:2015-07-04 10:57:25      阅读:262      评论:0      收藏:0      [点我收藏+]
技术分享
/* 队列的链式存储 */
/* with no header */
struct Node;
struct LinkQueue;
typedef struct Node *PtrToNode;
typedef struct LinkQueue *PtrTorf;
struct Node{
    ElementType X;
    PtrToNode Next;
};

struct LinkQueue{
    PtrToNode rear;
    PtrToNode front;
};

int
IsEmpty(PtrTorf PtrQ )
{
    return PtrQ->front == NULL;
}

ElemenType DeleQ(PtrTorf PtrQ )
{
    PtrToNode TmpCell;
    ElementType X;
    if( IsEmpty( PtrQ ) )
    {
        Error("队列是空");
        retutn;
    }
    TmpCell = PtrQ->front;
    X = TmpCell->Element;
    if( PtrQ->front == PtrQ->rear )
    {
        PtrQ->front = NULL;
        PtrQ->rear = NULL;
    }
    else
        PtrQ->front = TmpCell->Next;
    free( TmpCell );
    return X;
}

void
AddQ( PtrTorf PtrQ )
{
    PtrToNode TmpCell;
    TmpCell = malloc(sizeof(struct Node ));
    if(TmoCell == NULL )
        Error("out if space ");
    TmpCell->Next == NULL;
    TmpCell->Element = X;
    if( !(IsEmpy( PtrQ ))){//队列非空时,也只有rear再动
        PtrQ->rear->Next = TmpCell;
        PtrQ->rear = TmpCell;
    }
    else
        PtrQ->rear = Ptr->front = TmpCell;//队列的链式存储,front和rear都指向一处时,才表示有一个元素,如果都指向NULL就表示空
}
View Code

 

队列的链式存储---链表实现

原文:http://www.cnblogs.com/gabygoole/p/4620268.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!