728x90
🎯
스택
1. 데이터를 추가하면 맨 마지막 위치에 자리합니다.
2. 삭제를 하면 맨 마지막 위치의 데이터를 삭제합니다(삭제 데이터 반환).
구현 (파이썬)
class Node:
def __init__(self, item, next):
self.item = item
self.next = next
class Stack:
def __init__(self):
self.top = None
def push(self, item):
self.top = Node(item, self.top)
def pop(self):
if self.top is None:
return None
node = self.top
self.top = self.top.next
return node.item
def is_empty(self):
return self.top is None
728x90
'유물 > 알고리즘' 카테고리의 다른 글
<프로그래머스(파이썬)> 입국심사 (0) | 2022.04.07 |
---|---|
<프로그래머스(파이썬)> 정수 삼각형 (0) | 2022.04.07 |
<릿코드(파이썬)> 240. Search a 2D Matrix Ⅱ (0) | 2022.04.01 |
<프로그래머스(파이썬)> [3차] 파일명 정렬 (0) | 2022.03.31 |
<자료구조> 역순 연결 리스트 (0) | 2022.03.13 |