공부/알고리즘

원형 큐 알고리즘

zzangyeah 2024. 6. 15. 15:00
728x90

pseudocode

원형 큐 생성 : font, rear 0으로 초기화
createQUeue()
    cQ[n];
    front<-0;
    rear<-0;

공백상태 검사
isEmpty(cQ)
    if (front == rear) then return true;
    else return false;
end isEmpty()

포화상태 검사
isFull(cQ)
    if(((rear+1)mod n)==front) then return true;
    else return false;
end isFull()

원형 큐 삽입
enQueue(cQ, item)
    if (isFull(cQ)) then Queue_Full();
    else {
        rear <-(rear+1) mod n;
        cQ[rear]<item;
        }
    end enQueue()

원형큐삭제
deQueue(cQ)
    if(isEmpty(cQ)) then Queue_Empty();
    else {
        front<-(front+1) mod n;
        return cQ[front];
    }
    end deQueue()