๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœ’๏ธ Data Structures & Algorithms

[Data Structures & Algorithms] ํ(Queue)์˜ ์‘์šฉ๊ณผ ๋ฐํฌ(Deque)

by A Lim Han 2023. 6. 11.

๐ŸŽฉ ํ(Queue)์˜ ์‘์šฉ_1) ์šด์˜์ฒด์ œ์˜ ์ž‘์—… ํ

๐Ÿ’œ ํ”„๋ฆฐํ„ฐ ๋ฒ„ํผ ํ (Printer Buffer Queue)

: CPU์—์„œ ํ”„๋ฆฐํ„ฐ๋กœ ๋ณด๋‚ธ ๋ฐ์ดํ„ฐ ์ˆœ์„œ๋Œ€๋กœ ํ”„๋ฆฐํ„ฐ์—์„œ ์ถœ๋ ฅํ•˜๊ธฐ ์œ„ํ•ด ์„ ์ž…์„ ์ถœ ๊ตฌ์กฐ์˜ ํ ์‚ฌ์šฉ

 


 

๐Ÿ’œ ์Šค์ผ€์ค„๋ง ํ (Scheduling Queue)

: CPU ์‚ฌ์šฉ์„ ์š”์ฒญํ•œ ํ”„๋กœ์„ธ์„œ๋“ค์˜ ์ˆœ์„œ๋ฅผ ์Šค์ผ€์ค„๋งํ•˜๊ธฐ ์œ„ํ•ด ํ ์‚ฌ์šฉ

 


๐ŸŽฉ ํ(Queue)์˜ ์‘์šฉ_2) ์‹œ๋ฎฌ๋ ˆ์ด์…˜์—์„œ์˜ ํ์ž‰ ์‹œ์Šคํ…œ

: ์‹œ๋ฎฌ๋ ˆ์ด์…˜์„ ์œ„ํ•œ ์ˆ˜ํ•™์  ๋ชจ๋ธ๋ง์—์„œ ๋Œ€๊ธฐ ํ–‰๋ ฌ ๋ฐ ๋Œ€๊ธฐ ์‹œ๊ฐ„ ๋“ฑ์„ ๋ชจ๋ธ๋งํ•˜๊ธฐ ์œ„ํ•ด ํ์ž‰ ์ด๋ก (Queue Theory)์„ ์‚ฌ์šฉํ•˜๊ธฐ๋„ ํ•œ๋‹ค.

 


๐ŸŽฉ ๋ฐํฌ(Deque)๋ž€?

๊ธฐ์กด์˜ ํ 2๊ฐœ ์ค‘ ํ•˜๋‚˜๋ฅผ ์ขŒ์šฐ๋กœ ๋’ค์ง‘์— ๊ฒฐํ•ฉ์‹œํ‚จ ๊ตฌ์กฐ๋กœ, ํ์˜ ์–‘์ชฝ ๋์—์„œ ์‚ฝ์ž…๊ณผ ์‚ญ์ œ ์—ฐ์‚ฐ์„ ๋ชจ๋‘ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ™•์žฅํ•œ ์ž๋ฃŒ ๊ตฌ์กฐ๋ฅผ ๋ฐํฌ(Deque)๋ผ๊ณ  ํ•œ๋‹ค.

 


 

๐Ÿ’œ ๋ฐํฌ์˜ ์ถ”์ƒ ์ž๋ฃŒํ˜•

ADT deque

    // ๊ณต๋ฐฑ ์ƒํƒœ์ธ ๋ฐํฌ ์ƒ์„ฑ
    createDeque() ::= create an empty DQ;
    
    //๋ฐํฌ๊ฐ€ ๊ณต๋ฐฑ ์ƒํƒœ์ธ์ง€ ๊ฒ€์‚ฌ
    isEmpty(DQ) ::= if (DQ is empty) then return true
                    else return false;
   
    //๋ฐํฌ์˜ front ์•ž์— ์›์†Œ ์‚ฝ์ž…
    insertFront(DQ, item) ::= insert item at the front of DQ;
    
    //๋ฐํฌ์˜ rear ๋’ค์— ์›์†Œ ์‚ฝ์ž…
    insertRear(DQ, item) ::= insert item at the rear of DQ;
    
    //๋ฐํฌ์˜ front์— ์žˆ๋Š” ์›์†Œ ์‚ญ์ œ
    deleteFront(DQ) ::= if (isEmpty(DQ)) then return NULL
                        else
                        {
                            delete and return the front item of DQ
                        };
    
    //๋ฐํฌ์˜ rear์— ์žˆ๋Š” ์›์†Œ ์‚ญ์ œ
    deleteRear(DQ) ::= if (isEmpty(DQ)) then return NULL
                       else
                       {
                            delete and return the rear item of DQ
                        };
    
    //๋ฐํฌ์˜ front์— ์žˆ๋Š” ์›์†Œ ๋ฐ˜ํ™˜
     getFront(DQ) ::= if (isEmpty(DQ)) then return NULL
                        else
                        {
                            return the front item of DQ
                        };
    
    //๋ฐํฌ์˜ rear์— ์žˆ๋Š” item ๋ฐ˜ํ™˜
    getRear(DQ) ::= if (isEmpty(DQ)) then return NULL
                       else
                       {
                            return the rear item of DQ
                        };
                        
End deque