파이썬
5장 자료구조 2_ 리스트 vs 스택 vs 큐
Mara7
2022. 5. 14. 20:18
LIST
리스트를 스택으로 사용하기
스택 : last-in, first-out
삽입 : append() : 리스트 인덱스 마지막 위치에 값 삽입
삭제 : pop() : 리스트 인덱스의 마지막 위치 값 삭제
리스트를 큐로 사용하기
큐 : first-in, first-out
비효율적임 , 리스트 앞에 덧붙이거나, 앞에서 꺼내는 작업은 느림.
from collections import deque
queue = deque(["Eric", "John", "Michael"])
queue.append("Terry") # Terry arrives
queue.append("Graham") # Graham arrives
queue.popleft() # The first to arrive now leaves
queue.popleft() # The second to arrive now leaves
queue # Remaining queue in order of arrival
반응형
LIST