자료구조알고리즘 #파이썬 #스택 #노드 #stack #node
-
[파이썬, 자료구조 알고리즘] StackPython 2024. 7. 12. 01:16
Stack 빨래통에 빨래감을 담은 후 꺼내려고 할 때, 가장 마지막에 담은 빨래감을 가장 먼저 꺼내게 되듯이,데이터를 한 곳에서만 넣고 뺄 수 있고, 마지막에 넣은 데이터를 가장 먼저 꺼낼 수 있는 Last In First Out 자료 구조. 처음부터 구현을 할 수 있어야 한다고 해서 직접 해보기로. Stack에 들어가는 기본 단위를 Node이라고 한다. 이해하기 쉽게 Node를 빨래감이라고 하면,빨래감 노드은 두가지로 구성된다. 내가 갖고 있는 빨래감과 다음에 넣을 빨래감을 가리키는 역할.class 빨래감: def __init__(self, item, next) # 갖고있는 빨래감, 다음 빨래감을 가리키는 포인터 self.item = item self.next = next 그 다음은 스택(빨..