PTA - 6-1 带头结点的链队列的基本操作 (10 分)

Status QueueInsert(LinkQueue *Q,ElemType e){
    LNode* insertNode = (LNode*)malloc(sizeof(LNode));
    if(insertNode == NULL) return ERROR;
    
    insertNode->data = e;
    insertNode->next = NULL;
    
    Q->rear->next = insertNode;
    Q->rear = insertNode;
    return OK;
}

Status QueueDelete(LinkQueue *Q,ElemType *e){
    if(Q->front == Q->rear) return ERROR;
    
    LNode* pHead = Q->front->next;
    *e = pHead->data;
    Q->front->next = pHead->next;
    
    if(pHead == Q->rear){
        Q->rear = Q->front;
    }
    free(pHead);
    return OK;
}

posted @ 2021-11-28 15:29  openallzzz  阅读(46)  评论(0编辑  收藏  举报  来源