stack structure

/

stack structure(スタック構造)について

タグ stack


概要

  • 最後に入ったものから最初に出す
    • “last-in, first-out”

pythonでの実装

>>> stack = [3, 4, 5]
>>> stack.append(6)
>>> stack.append(7)
>>> stack
[3, 4, 5, 6, 7]
>>> stack.pop()
7
>>> stack
[3, 4, 5, 6]
>>> stack.pop()
6
>>> stack.pop()
5
>>> stack
[3, 4]
  • 現実的な使用ではcollection.dequeモジュールを使用する

参考