반응형
● 스택
ㅇ 한쪽 끝에서만 자료를 넣거나 뺄 수 있는 구조
ㅇ 가장 나중에 쌓은 데이터를 가장 먼저 빼내는 데이터 구조
ㅇ LIFO(Last-In, First-Out), FILO(First-In, Last-Out)
ㅇ 컴퓨터 내부의 프로세스 구조의 함수 동작 방식의 활용, 재귀함수
VisuAlgo - Linked List (Single, Doubly), Stack, Queue, Deque
VisuAlgo is free of charge for Computer Science community on earth. If you like VisuAlgo, the only payment that we ask of you is for you to tell the existence of VisuAlgo to other Computer Science students/instructors that you know =) via Facebook, Twitter
visualgo.net
● 주요 기능
ㅇ push() : 데이터를 스택에 넣기
ㅇ pop() : 데이터를 스택에서 꺼내기
● 장점, 단점
ㅇ 장점
- 구조가 단순해서 구현이 쉽다
- 데이터 저장/읽기 속도가 빠르다
ㅇ 단점
- 데이터 최대 개수를 미리 정해야 한다
- 저장 공간의 낭비가 발생할 수 있음
● 구현
class Stack:
def __init__(self):
self.stack_list = list()
def push(self, data):
self.stack_list.append(data)
def pop(self):
if len(self.stack_list) == 0:
print("empty")
return
data = self.stack_list[-1]
del self.stack_list[-1]
return data
push와 pop을 구현해보았다