
[Algorithm] 파이썬에서 스택(Stack)과 큐(Queue)의 사용
·
Computer Science/Algorithm
스택 (Stack) - 선입후출(First-In Last-Out) 구조 또는 후입선출 구조 - 박스 쌓기에 비유할 수 있다 🔥 스택 with Python - 별도의 라이브러리 없이 기본 리스트에서 append(), pop() 메서드를 이용하여 사용 가능하다 stack = [] stack.append(5) stack.append(2) stack.append(3) stack.pop()# 3 stack.append(1) stack.append(4) stack.pop()# 4 print(stack[::-1]) # 최상단 원소부터 출력 # [1, 2, 5] 큐 (Queue) - 선입선출(First-In First-Out) 구조 - 대기 줄에 비유할 수 있는 '공정한' 자료구조라고 할 수 있다 🔥 큐 with Py..