data structure,

Stack๊ณผ Queue

Ella Ella Follow Nov 20, 2021 ยท 1 min read
Stack๊ณผ Queue
Share this

๐Ÿ“š

๊ฐœ๋… 2๏ธโƒฃ Stack vs Queue

[1] Stack

  • ์„ ํ˜• ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ
  • ์‚ฝ์ž… : ๋ฆฌ์ŠคํŠธ์˜ top ์—์„œ๋งŒ ๊ฐ€๋Šฅํ•จ
  • ์‚ญ์ œ : ๋ฆฌ์ŠคํŠธ์˜ top ์—์„œ๋งŒ ๊ฐ€๋Šฅํ•จ
  • LIFO(Last In First Out) : ๊ฐ€์žฅ ๋‚˜์ค‘์— ๋„ฃ์€ ๊ฒƒ์ด ๊ฐ€์žฅ ๋จผ์ € ๋‚˜์˜ด
  • ์Šคํƒ์— ์›์†Œ๋ฅผ ์‚ฝ์ž…ํ•˜๋Š” ํ–‰์œ„ : push
  • ์Šคํƒ์—์„œ ์›์†Œ๋ฅผ ์ œ๊ฑฐํ•˜๋Š” ํ–‰์œ„ : pop
  • ํ™œ์šฉ ์˜ˆ์‹œ
    • ์›น ๋ธŒ๋ผ์šฐ์ฆˆ ๋ฐฉ๋ฌธ๊ธฐ๋ก(๋’ค๋กœ ๊ฐ€๊ธฐ) : ๊ฐ€์žฅ ๋‚˜์ค‘์— ์—ฐ ํŽ˜์ด์ง€๋ถ€ํ„ฐ ๋‹ค์‹œ ๋ณด์—ฌ์คŒ
    • ์—ญ์ˆœ ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ : ๊ฐ€์žฅ ๋‚˜์ค‘์— ์ž…๋ ฅ๋œ ๋ฌธ์ž๋ถ€ํ„ฐ ์ถœ๋ ฅํ•จ
    • ์‹คํ–‰ ์ทจ์†Œ(undo) : ๊ฐ€์žฅ ๋‚˜์ค‘์— ์‹คํ–‰ํ•œ ๊ฒƒ๋ถ€ํ„ฐ ์‹คํ–‰ ์ทจ์†Œํ•จ
    • ํ›„์œ„ ํ‘œ๊ธฐ๋ฒ• ๊ณ„์‚ฐ
    • ์ˆ˜์‹ ๊ด„ํ˜ธ ๊ฒ€์‚ฌ

[2] Queue

  • ์„ ํ˜• ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ
  • ์‚ฝ์ž… : ๋ฆฌ์ŠคํŠธ์˜ rear ์—์„œ๋งŒ ๊ฐ€๋Šฅํ•จ
  • ์‚ญ์ œ : ๋ฆฌ์ŠคํŠธ์˜ front ์—์„œ๋งŒ ๊ฐ€๋Šฅํ•จ
  • FIFO(First In First Out) : ๊ฐ€์žฅ ๋จผ์ € ๋„ฃ์€ ๊ฒƒ์ด ๊ฐ€์žฅ ๋จผ์ € ๋‚˜์˜ด
  • ํ์— ์›์†Œ๋ฅผ ์‚ฝ์ž…ํ•˜๋Š” ํ–‰์œ„ : enqueue
  • ํ์—์„œ ์›์†Œ๋ฅผ ์ œ๊ฑฐํ•˜๋Š” ํ–‰์œ„ : dequeue
  • ํ™œ์šฉ ์˜ˆ์‹œ
    • ํ”„๋ฆฐํ„ฐ์˜ ์ธ์‡„ ๋Œ€๊ธฐ์—ด
    • ์€ํ–‰ ์—…๋ฌด
    • ์ฝœ์„ผํ„ฐ ๊ณ ๊ฐ ๋Œ€๊ธฐ๊ธฐ๊ฐ„
    • BFS
    • ์บ์‹œ(Cache) ๊ตฌํ˜„

[์ฐธ๊ณ  ์‚ฌ์ดํŠธ]
1: https://www.geeksforgeeks.org/difference-between-stack-and-queue-data-structures/

Join Newsletter
Get the latest news right in your inbox. We never spam!
Ella
Written by Ella Follow
Android Developer, love to explore new ideas and write on my morning coffee!