let's get IT with DAVINA ๐Ÿ’ป

[์ž๋ฃŒ๊ตฌ์กฐ/์„ ํ˜•๊ตฌ์กฐ] ๋ฑ ๋ณธ๋ฌธ

DEV_IN/Algorithm

[์ž๋ฃŒ๊ตฌ์กฐ/์„ ํ˜•๊ตฌ์กฐ] ๋ฑ

๋‹ค๋นˆ์น˜์ฝ”๋“œ๐Ÿ’Ž 2023. 3. 9. 20:18

Deque (Double Ended Queue)

  • ์–‘์ชฝ ๋์—์„œ ์‚ฝ์ž…/์‚ญ์ œ๊ฐ€ ์ „๋ถ€ ๊ฐ€๋Šฅํ•œ ์ž๋ฃŒ๊ตฌ์กฐ

๋ฑ์˜ ์„ฑ์งˆ

  1. ์›์†Œ์˜ ์ถ”๊ฐ€ → O(1)
  2. ์›์†Œ์˜ ์ œ๊ฑฐ → O(1)
  3. ์ œ์ผ ์•ž/๋’ค์˜ ์›์†Œ ํ™•์ธ → O(1)
  4. ์ œ์•Œ ์•ž/๋’ค๊ฐ€ ์•„๋‹Œ ๋‚˜๋จธ์ง€ ์›์†Œ๋“ค์˜ ํ™•์ธ/๋ณ€๊ฒฝ์ด ์›์น™์ ์œผ๋กœ ๋ถˆ๊ฐ€๋Šฅ

๊ตฌํ˜„

const int MX = 1000005;
int dat[2*MX+1]; //์•ž๋’ค๋กœ ๋‹ค ์‚ฝ์ž…์ด ๊ฐ€๋Šฅํ•ด์„œ ์–‘์ชฝ์œผ๋กœ ํ™•์žฅํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฐฐ์—ด์˜ ํฌ๊ธฐ๋Š” 2*MX+1
int head=MX, tail=MX;

 

Comments