Skip to content

Latest commit

Β 

History

History
39 lines (25 loc) Β· 945 Bytes

Stack_Queue.md

File metadata and controls

39 lines (25 loc) Β· 945 Bytes

Stack, Queue (μŠ€νƒ, 큐)

Stack

ν›„μž…μ„ μΆœ(LIFO)둜 λ™μž‘ν•˜λŠ” 자료ꡬ쑰. λ‚˜μ€‘μ— λ“€μ–΄μ˜¨ 게 λ¨Όμ € λ‚˜κ°„λ‹€.

νŒŒμ΄μ¬μ—μ„œλŠ” λ‹€μŒκ³Ό 같이 리슀트 μžλ£Œν˜•μ„ 톡해 μ‚¬μš©ν•  수 μžˆλ‹€.

Queue

μ„ μž…μ„ μΆœ(FIFO) ꡬ쑰라고도 ν•œλ‹€. λ¨Όμ € λ“€μ–΄μ˜¨ 게 λ¨Όμ € λ‚˜κ°„λ‹€.

νŒŒμ΄μ¬μ—μ„œμ˜ μŠ€νƒ, 큐

μŠ€νƒ

νŒŒμ΄μ¬μ—μ„œ μŠ€νƒμ€ λ‹€μŒκ³Ό 같이 리슀트 μžλ£Œν˜•μ„ 톡해 μ‚¬μš©ν•  수 μžˆλ‹€.

stack = []
stack.append(0) # push [0]
stack.append(1) # push [0, 1]
stack.pop() # pop [0] λ°˜ν™˜κ°’μ€ 1

큐 (덱)

νŒŒμ΄μ¬μ—μ„œλŠ” collections λͺ¨λ“ˆμ˜ deque(덱)을 μ΄μš©ν•΄ 큐처럼 μ‚¬μš©ν•œλ‹€.

λ±μ΄λž€, μŠ€νƒκ³Ό 큐λ₯Ό ν•©μΉœ 자료ꡬ쑰둜 μ–‘ λ°©ν–₯μ—μ„œ μ‚½μž…/μ‚­μ œκ°€ κ°€λŠ₯ν•˜λ‹€.

from collections import deque

queue = deque()
queue.append(0) # push [0]
queue.append(1) # push [0, 1]
queue.popleft() # pop [1] λ°˜ν™˜κ°’μ€ 0