PTA - 6-2 循环队列入队出队 (70 分)

// squeue是循环队列的地址
void EnQueue_seq(SeqQueue squeue, DataType x){
    if((squeue->r + 1) % squeue->Max == squeue->f){
        printf("It is FULL Queue!");
    }else{
        squeue->elem[squeue->r] = x;
        squeue->r = (squeue->r + 1) % squeue->Max;
    }
}

void DeQueue_seq(SeqQueue squeue){
    if(squeue->f == squeue->r){
        printf("It is empty queue!");
    }else{
        squeue->f = (squeue->f + 1) % squeue->Max;
    }
}

DataType FrontQueue_seq(SeqQueue squeue){
    if(squeue->f == squeue->r){
        printf("It is empty queue!");
    }
    return squeue->elem[squeue->f];
}
posted @ 2021-11-28 15:30  openallzzz  阅读(53)  评论(0编辑  收藏  举报  来源