Data Structure

[Data Stucture] Stack(μŠ€νƒ) μ‚¬μš©λ²•

An effort will never betray 😎 2020. 2. 22. 17:00
λ°˜μ‘ν˜•
  • C++ STL 쀑 ν•˜λ‚˜μΈ Stack μ‚¬μš©λ²•μž…λ‹ˆλ‹€.

Stack μ΄λž€?

  • Stack은 LIFO(Last in First Out) 으둜 μ„€κ³„λœ container μž…λ‹ˆλ‹€.

  • μ œλ„ˆλ¦­ν•˜κ²Œ κ΅¬ν˜„λ˜μ–΄ μžˆμ–΄ μ–΄λ– ν•œ μ›μ†ŒλΌλ„ 멀버 ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•˜μ—¬ push, pop ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

  • #include < stack > 을 μ„ μ–Έν•΄μ•Ό stack 라이브러리λ₯Ό μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.


κΈ°λ³Έ ν•¨μˆ˜

empty ( )

  • μŠ€νƒμ΄ λΉ„μ–΄ μžˆλŠ”μ§€ ν™•μΈν•˜λŠ” ν•¨μˆ˜
  • if stack is empty, then return 1 else 0

size ( )

  • μŠ€νƒμ˜ 크기λ₯Ό λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜
  • return size_type (unsigned int)

top ( )

  • μŠ€νƒμ˜ λ§ˆμ§€λ§‰ μ›μ†Œλ₯Ό λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜
  • return reference top element

push ( element )

  • μŠ€νƒμ— μ›μ†Œλ₯Ό μΆ”κ°€ν•˜λŠ” ν•¨μˆ˜

pop ( )

  • μŠ€νƒμ˜ λ§ˆμ§€λ§‰ μ›μ†Œλ₯Ό μ‚­μ œν•˜λŠ” ν•¨μˆ˜

swap ( )

  • 두 개의 μŠ€νƒμ„ λ°”κΎΈλŠ” ν•¨μˆ˜

operator =

  • λŒ€μž…μ—°μ‚°μž κ°€λŠ₯

relational operator

  • μŠ€νƒμ˜ 크기와 상관없이 ν•˜λ‚˜μ”© μ›μ†Œλ₯Ό λΉ„κ΅ν•΄κ°€λ©΄μ„œ 확인

μ‹€μŠ΅

κ²°κ³Ό

  • μΆ”κ°€λ‘œ κΆκΈˆν•œ μ μ΄λ‚˜ μˆ˜μ •ν•  사항 있으면 λŒ“κΈ€λ‘œ λ‚¨κ²¨μ£Όμ„Έμš”.
λ°˜μ‘ν˜•